-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Import error after build #15
Comments
yes, you are loading multiple copies of react. Download the "test.zip" file here: https://github.com/projectstorm/react-diagrams/releases and that should show you how to get up and running. This example uses webpack to show you how to get it up and running |
Seems it doesn't work.
|
so when you yarn link, the node_modules are not flattened. That means that there is a react folder in both the react-diagrams project as well as your own project, and if those versions are different or they are different paths, react will be included twice. aka yarn link = symlink which means you have 2 copies of react. To fix this, add this to your webpack config: externals: {
"react": 'react',
"lodash": {
commonjs: 'lodash',
commonjs2: 'lodash',
amd: '_',
root: '_'
}
}, |
this will force react to always only load the react that is in the root of your project, and not the react inside the symlink as well, does this make sense? |
But there is this code already in your webpack config |
yes, but i assume you are importing this into your own project. So essentially:
So why are you yarn linking in the first place is what I'm asking, there should be no need to yarn link, unless you want to locally develop the library itself, in which case you will need the 'externals' in your own config. This problem is not specific to storm-react-diagrams, its a problem with your development environment / webpack setup. To see more about why you are getting this error, please see: |
Thank you for such full answer |
It's weird ( Your library doesn't contain a React, right? As far as it is excluded in |
If I try to use link with test2 i got this =/
|
The best way i can explain this is:
when webpack does an include it will see the require('react') / import "react" inside my minified bundle and will then look for it at "B" because you also now have a node_modules folder there.
Which is why you don't need the 'external' command in the above structure.
test2 was done quite a while ago, I wanted you to see this more for how to setup a project that uses this library with webpack. The error you are getting here is now a runtime error, so unless you show me your code, I cannot help you with this unfortunately. |
Yes, thanks again for the explanation, but I got the problem, but wondering about a solution.
|
yeah that would work as well because the react is now shared across both directories. But next time, you should just add the externals to YOUR webpack config, and then you won't have this issue :) |
oh wait, sorry i think i messed this up actually lol what ive been meaning to say the whole time was https://webpack.js.org/configuration/resolve/#resolve-alias |
I did, but it didn't work out for me. |
sorry for the confusion this whole time, the problem as i explained it was the same, its just that ive been telling you to use the wrong directive to solve it. |
Wouldn't declaring react as a |
no, because peer dependencies are bad :P |
but also because this issue has since been solved? |
@dylanvorster hi, I'm trying use babel-plugin-lodash to reduce the size of lodash chunk in my project. How can I resolve this scenario? (you says peer dependencies are bad, why?) |
I've got an error while importing brand new built library.
It completely ok with importing your git version.
But I got an error after importing a library just right after built with
webpack
command. Even if no any single change.Do you have any idea what could be wrong?
The text was updated successfully, but these errors were encountered: