wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

node modules rt-import issue #230

Closed mittalabhas1 closed 6 years ago

mittalabhas1 commented 7 years ago

I'm trying to import few node modules using rt-import.

<rt-import name="Link" from="react-router" />
<rt-import name="default" as="ArrowIcon" from="material-ui/svg-icons/action/trending-flat" />

which should compile to

import { Link } from 'react-router';
import ArrowIcon from 'material-ui/svg-icons/action/trending-flat';

But it errors out, here's the stack trace

Module build failed: Error
    at Function.buildError [as build] (PROJECT_PATH/node_modules/react-templates/src/RTCodeError.js:83:12)
    at convertHtmlToReact (PROJECT_PATH/node_modules/react-templates/src/reactTemplates.js:330:31)
    at _.map.child (PROJECT_PATH/node_modules/react-templates/src/reactTemplates.js:420:26)
    at arrayMap (PROJECT_PATH/node_modules/lodash/lodash.js:660:23)
    at Function.map (PROJECT_PATH/node_modules/lodash/lodash.js:9571:14)
    at convertHtmlToReact (PROJECT_PATH/node_modules/react-templates/src/reactTemplates.js:419:28)
    at parseAndConvertHtmlToReact (PROJECT_PATH/node_modules/react-templates/src/reactTemplates.js:646:12)
    at convertRT (PROJECT_PATH/node_modules/react-templates/src/reactTemplates.js:659:18)
    at Object.convertTemplateToReact (PROJECT_PATH/node_modules/react-templates/src/reactTemplates.js:608:12)
    at Object.module.exports (PROJECT_PATH/node_modules/react-templates-loader/index.js:14:24)
 @ ./app/client/components/Landing/LandingPage.jsx 26:0-127
 @ ./app/client/routes/ClientRouter.jsx
 @ ./app/main.js
 @ multi webpack/hot/only-dev-server webpack-dev-server/client?http://0.0.0.0:3000 es5-shim/es5-shim es5-shim/es5-sham babel-polyfill ./app/main.js ./app/assets/stylesheets/application.scss

Is import of node modules not supported in rt-import?

mittalabhas1 commented 7 years ago

Okay this was easy, I checked the error at the specified line and it says rt-import must be a top level node, but doesn't this violate the rule that multiple parent nodes ain't allowed? Also do you think we can print out the error message along with the trace, so the error becomes obvious to the user?

nippur72 commented 7 years ago

rt-import nodes are not considered "true nodes" as they are indeed removed from the final output, so in this sense they don't violate the rule of one single root node.

As for the error, I don't know why webpack is not picking it... it should print as any other error.

mittalabhas1 commented 6 years ago

Got it. Understand your point on the final output. Yeah, the webpack not picking the error is kinda annoying as the hot build just fails and you just have to go through all the recent changes.