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
React application fails to compile when using a JS library #9275
Comments
+1 Was able to resolve for now by including a
|
Yeah, the problem is that the JS lib is set up to use "tsc" as its compiler and thus doesn't include a babelrc, but React applications are compiled with babel and don't know what to do with those files when the babelrc is missing. You can get a successful production build going by turning off the "buildLibsFromSource" option which will then cause the JS lib to be built separately using its own compiler, but that solution doesn't help you in dev mode. When serving the React app with the dev server it tries to bundle the whole thing together and ignores the buildLibsFromSource option, so the babelrc is required for dev mode. I think that's also an interesting broader question as well, shouldn't "buildLibsFromSource: false" also affect how running the application in dev mode works? |
You would hope dev/testing/building was consistent. When I get a bit of time to breath I'll dig into a bit and try and get a PR out. In the meantime, I also had to swap out the default module.exports = {
displayName: "my-app",
preset: "../../../../jest.preset.js",
transform: {
"^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nrwl/react/plugins/jest",
"^.+\\.[tj]sx?$": "ts-jest",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory:
"../../../../coverage/packages/my-app",
}; |
It sounds like this may resolve the buildLibsFromSource inconsistency |
Fixed by #10055 |
For any newcomers to |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
A freshly generated react application in a brand new Nx repo will fail to compile when attempting to use a library from the same repo that was generated using the "@nrwl/js" package.
Expected Behavior
I would expect that a js package would work in any application. Library packages generated this way work fine in Node applications.
Steps to Reproduce
nx g @nrwl/react:application react-app
nx g @nrwl/js:library js-lib
nx serve <react app>
Failure Logs
Environment
Edit: After comparing the differences between a lib generated with
@nrwl/js
and one generated with@nrwl/react
, it seems the key difference is that thejs
one doesn't include a.babelrc
file. Is this intentional?The text was updated successfully, but these errors were encountered: