-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
symbolic link duplicate module load #554
Comments
@sokra webpack should probably resolve symbolic links with fs.realpath? |
We have also just spent a good while debugging a problem related to this. We have some shared code that is symlinked into a couple different repos, we use an |
This issue destroyed my productivity for a whole day once the race condition for loading modules caused two Handlebars to load in a particularly bad order. It isn't obvious at all that syn linking would cause anything like this issue so it's very painful to debug. Please push a fix so you don't cause more strangle-worthy frustration for other developers. |
@MSeal calm down. The solution is not as clear as you think. Maybe someones is relying on that webpack handles them as distinct paths... |
Well a warning or notice somewhere would at least be a good first step if there's duplicate paths being generated because of symlinking. Regardless of if someone is relying on duplicate pathing, it's hard to argue that double loading handlbars is the correct behavior as you wipe out the global state after the race condition resolves. |
Ran into this as well -- particularly tricky for isomorphic apps because
You can require a module like this:
This is really nice for large apps, because you don't have to deal with relative paths. But as noted above, it creates a ton of duplicate paths in Webpack (over 1000 in my case), which doesn't behave the same as NPM here. |
@irvinebroque I see... but if you used the non-relative style throughout the whole app, there wouldn't be duplicate paths. @sokra what do you think? Should they be resolved? I think, they should... |
I think this can be solved... |
@jhnns - true, but that means if one person uses a relative path by mistake, it causes duplicate requires without any warning or error. Basically setting yourself up for something failing silently. Even though I don't agree with the way NPM handles this with symlinks, IMHO it's really important to be able to mimic NPM's behavior. I may be wrong here, but I think most people are more comfortable adding extra configuration to |
@irvinebroque I agree. |
The symbol link problem is still exists. I already update webpack to 1.10.1. |
i'm using 1.10.5 and also encounter this issue |
Could anyone solve this problem. Now I install local package instead of |
I'm confused how this works... I'm trying to develop a bugfix on a fork of |
I have the same problem where a second copy of react is bundled along with the symlinked module (via npm link) even though the parent module already has it installed. If I delete the react module from the symlinked module's node_modules dir, webpack errors out because the symlinked module can no longer find react and apparently webpack doesn't detect that the parent already has it installed. Both have the same version of react, 0.13.3. I am using the latest Webpack 1.12.0. |
|
…rything before running webpack Related to changes made back in webpack/webpack#554 (essentially, undoing them for our case)
FYI, for others that come here. I was in a situation like @jhnns mentioned, where I'm relying on not resolving the symlinks (otherwise relative paths inside a symlinked module didn't work, because the resolved symlink ends up in a different directory than the file referred to by the relative path). Fortunately, I figured out how to get around this by writing a Webpack plugin that prevents ResultSymlinkPlugin from running: timmfin/broccoli-webpack-cached@5dfcd31 |
I have been in the same predicament from others in here, i am npm linking a project that has react as external and its duplicating it, how are you guys solving this? |
Ran into this issue as well. I'm using |
Exact same problem right now. |
Are there any workarounds for this yet? Trying to set up a dev environment for one of my packages, which is required by a larger project, which in turn contains a gulp build process with webpack. Using npm link is resolving some dependencies twice. |
One workaround I've found is that you have to go into your parent project's node_modules and npm link all the dependencies that are shared with the modules you want to work on locally. Example using React library:
Then you are guaranteed that both the parent project and the child module you are working on locally will use the same lib. After you are done make sure to unlink everything. It's a huge headache when developing locally with modules. As much as I love the flexibility of Webpack, I never had these symlink/duplicate issues when using Browserify. I hope that this information helps people with this problem. |
We are working around this by npm installing the local git repo instead of using npm link. Our repositories are siblings in the main folder, so instead of using npm link, we make changes in one project and then in the other project: The only drawback we have seen is that we sometimes forget to update the parent's package file / dependencies before merging changes to the parent. |
cc @neoziro is your shiny new module fixing this? if so, how? |
@vvo my module only watch a folder and reinstall it in your current project if a file change, it's simple and it fixes all npm link issues. It's exactly the solution proposed by @SonofNun15. So if you want to automatize it : https://github.com/neoziro/npm-sync It's currently not very robust and stable. But I am open to every contributions! |
Within the context of npm link and react development the following worked for me as a work around: resolve: {
modulesDirectories: ["node_modules"],
alias: {
"react": NODE_MODULES_DIR + "/react",
... PS: I only have this issue w$ndows |
I'm having this same issue with |
Well, our current solution is to use a file sync tool (Free File Sync: http://www.freefilesync.org/) to copy the source folders into the npm dependency. This was a fast and easy way to get the desired functionality without the headaches of npm link and / or local npm install. |
@jessepollak (and for anyone else struggling with an Until this is addressed in a more permanent way, I've found a really good solution is to share a single It sounds a bit hacky, but after you get over the shock, it comes with a number of benefits. As long as your packages share the same dependency version requirements (i.e. one doesn't rely on an outdated module), simply creating a symbolic link to the first package's I've found this is particularly valuable for monorepo projects with multiple similar packages because it also slashes install time and total dependency weight significantly. See bitpay/icv2/package.json for our post-install script (and a working example monorepo). Basically:
Each |
@timmfin proposed solution that worked for us very well. I want not resolving symlinks to be default behavior of webpack. |
based on the suggestion of @timmfin I've come to a slightly different setup that's using for me. Instead of having a first module as the main source of a single shared |
I looked at trying to implement @timmfin's solution, but I couldn't see how it would slot in or work with exsiting projects I'm working with. The simpler solution was to npm link the react in the parent project to the child project, as per #554 (comment) - Figure others may find this information useful. |
I also tried using @timmfin's solution, however it failed for my project, because my project uses Webpack 4.41.2, and Webpack 4 does not have a You could probably achieve the same thing by swapping Instead of using a hook, I just monkey-patched the SymlinkPlugin class to disable its "apply" function. To do so, add this to the top of your
Some other noteworthy additions/alternatives:
|
I am using handlebars-loader and when node_modules folder is linked from some other location Handlebars.SafeString is loaded from two location moduleA.SafeString and moduleB.SafeString
bundle if you search inside of this bundle you will find two instance of function SafeString
I have created demo so you can reproduce
https://github.com/feroc1ty/webpack-symbolic-link-bug
The text was updated successfully, but these errors were encountered: