-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Babel JSX Syntax error when importing from a linked library #5100
Comments
Hey @FelixKuehl, we're really sorry about this! As mentioned in #5024, our monorepo support was incomplete and we think it would create more issues for our users in long term if we shipped it in that state. On the other hand, the 2.x branch has stalled for many months, and we were worried it would never get shipped. So we made a difficult decision to remove some of the features that existed in 2.0 earlier alphas in order to ship a stable 2.0 within two weeks. We'll offer migration strategies that you could use to unblock your migration to 2.x, but they'll likely include introducing another compiler like |
Hey @gaearon, thank you for your fast reply. This actually is quite a bummer for our current setup. We did enjoy developing cra powered applications in a monorepo due to the flexibility and the productive development workflow it gave us. Personally I have no experience with |
Yeah I understand why it's useful very well. It was just half-baked, especially with regards to how testing works, or how to opt out certain packages from compilation. @Timer can give you some pointers. |
@gaearon Thanks for explaining. I will take a look at projects like |
Hey @FelixKuehl! I'll probably be drawing up some more extensive documentation here soon. |
As an Update for all those having the same issue:
Another problem I stumbled across, that might be interesting for @Timer's migration proposals or create react app itself, was the way ESLint handles locally symlinked dependecies. With cra's current ESLint setup, everything within the "node_modules" folder gets ignored by ESLint as expected. However, if a dependency is symlinked locally (Yarn Workspace, Lerna, npm link, etc.) the path is resolved first and then checked against the eslintignore settings and therefore not excluded from linting. This results in ESLint errors showing up in your create react app when consuming a locally linkend library (Or more precisely its "dist" folder). A quick fix for this was using I will take a look at |
Hmm, ESLint resolving symlinks sounds like a bug. Can we turn this feature off? |
This bug is referenced in webpack-contrib/eslint-loader#165, webpack-contrib/eslint-loader#202 and webpack/webpack#985. I am not a webpack expert but setting |
@Timer following @gaearon's suggestion, I spend the last day experimenting with nwb as a compiler. The setup I came up with, seemed quite decent to me. I put up an example repo here: https://github.com/FelixKuehl/cra-monorepo So what did I do? (See https://github.com/FelixKuehl/cra-monorepo/blob/master/README.md for details) Update:Form commit FelixKuehl/cra-monorepo@0d21eb5 on, this repo uses babel to watch and compile the libraries. Also I switched to using Styleguidist over Storybook. |
@FelixKuehl in terms of performance, a couple of questions:
|
I currently using a babel --watch to achieve this rather than nwb (haven't had time to evaluate nwb/create-react-library) and it works fine from limited testing. (obviously you'll need your own babel config). |
At the moment it is recompiling the entire library on every code change. Sadly this cannot really be avoided when using nwb. It would be trivial to detect changes to assets and css / scss files (nodemon does that automaticly) and copy those without any recompilation. That would also enable the create react app to show style changes without recompiling. I am currently trying a
Yes ist does. I will update the example repo once I am happy with my final solution. At the moment I feel like I am going to build a simple container around a babel watch process. |
@bugzpodder At first I kind of liked the idea of using a library like nwb over using babel directly but
pretty much gets the job done. |
Hello all! I have been searching for a solution to my problem, and this seems to be the most relevant. Please let me know if this doesn't fit with this open issue. Goals:I am building two separate repositories. One will be a page which will import other React Components as npm packages once published. So currently I have a local repository that depends on another. For development, I am attempting to link them with Versions:
Circumstances:
I tried adding
This did not help.
Concerns:This seems to be either a Babel or Webpack issue concerning |
An update on my issue for future reference if someone may have a similar issue: The code for the Hopefully that was clear and helpful. |
I have got the issue (ref: https://stackoverflow.com/questions/56680612/react-script-compatibility-issue-with-third-party-node-module) which is very similar to @irmerk @gaearon @Timer i am not sure if this is out of the scope of cra 2.1.8 because this issue look like babel/webpack config issue and in cra we are not suppose to make any changes in config. |
I have got the exact issue as @chrisdel101 . Any updates on resolving the compilation error? |
We've had quite some time figuring this one out, but I think we found the reason and solution. Check this out guys - I bet you'll be blown away. So, when CRA tries to transpile your package, it uses babel to transpile JSX code to commonjs. Last versions of babel transpilers have big troubles with unnamed exports. So when you try and import your default as unnamed export (for example But we do not see this error, 'cause of CRA bundle. This error shows in console, for example, when we try and configure babel with webpack in monorepo by hand. The solution, that worked for me and my colleagues is this one:
And that's it. This worked for us beautifully. Special thanks to this hero, |
I have the same issue integrating with react native mono repo. It has issues with external libraries in the react native repo, and I also had the suggested structured
But it doesn't work because it is symlinked by lerna. |
any updates? |
This comment has been minimized.
This comment has been minimized.
any updates on this? |
I have the same issue when using a component from node_modules. Error is not happening when loading the component from the current working project itself.
When I change
|
It seems that this is all expected behavior, as Dan aka @gaearon says here #5103 (comment).
So this issue will likely never be solved within create-react-app. The external library maintainer should serve a transpiled code i guess. Also see https://stackoverflow.com/a/57762228/4840661:
|
Is this a bug report?
Yes
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
(Write your answer here if relevant.)
Environment
Running
npx create-react-app --info
does not seem to work. Getting:However I am using:
Node v8.11.3
Yarn 1.9.4
npm 6.4.1
react-scripts 2.0.0-next.2150693d
Steps to Reproduce
This used to work with react-scripts 2.0.0-next.a671462c
Expected Behavior
The app should compile just fine as it used to in 2.0.0-next.a671462c
Actual Behavior
Application fails to compile with "Syntax error: Unexpected token" in the component, that was attempted to be imported from the other application.
To me it seems like the babel loader is somehow not transpiling the imported component.
Reproducible Demo
https://github.com/FelixKuehl/cra-alpha-issue-example
The text was updated successfully, but these errors were encountered: