My project depends on a package that works perfectly when installed normally, but when I npm link
that package for local development, webpack fails finding dependencies like so:
[14:38:15] Version: webpack 1.5.3
Asset Size Chunks Chunk Names
tcc-ip-client.bundle.js 2690831 0 [emitted] client
tcc-ip-client.bundle.js.map 3223307 0 [emitted] client
ERROR in ../blah/src/js/utils/features.js
Module not found: Error: Cannot resolve module 'foobar/src/js/utils/endpoint' in /Users/josephpea/src/blah/src/js/utils
@ ../blah/src/js/utils/features.js 10:0-109:2
http://webpack.github.io/docs/troubleshooting.html#npm-linked-modules-doesn-t-find-their-dependencies
Same here, wondering if yarn is the issue.
Update: happens with npm as well.
Worked for me: Turn off symlink resolution in webpack via
resolve: { symlinks: false }
.Credit to this answer in #1866.
Turning off symlink resolution also makes it so webpack can’t watch for changes in the linked dependency 🙁 Any other solutions?
Actually I’m still having this problem, where I do
npm link a-package
to another one i’m working on. The symlink works fine but some dependencies inside that linked package don’t get resolved…It’s on Webpack”: “4.8.3”.
Any ideas?
@mesqueeb, I also still experienced this. Tried to play with the
symlinks
property but it didn’t help.What I ended up doing is looking through the
node_modules
folder, and if a folder was in fact a symlink, I would add the resolved address +node_modules
to themodules
array.For example something like this:
Yeah, what I do is usually
npm i
all dependencies of the package I’m linking to in the package I’m working on. Works like a charm.Can we re-open this issue?
I adapted @yuvke ‘s solution, making it sync and supporting scoped packages. See this gist for a webpack config example.
How is this issue still closed when the only solution is a noisy workaround?
@xthilakx that‘s not an option in the case HMR is needed where webpack needs to watch updates inside of the linked package. This is necessary when developing a library together with the client app.
#811 (comment)
This issue should be reopened as it is not properly solved. A module that is linked cannot be debugged with symlinks disabled.
In my case following webpack config worked:
for development mode –
resolve: { modules: [path.resolve("./node_modules")] },
for production mode –
resolve: { symlinks: false, modules: [path.resolve("./node_modules")] }
Note, I have disabled babel for development and HMR.
Also my imported module was in ES6 (not transpiled).
@fabb I understand that it would be awesome to HMR from the linked package, but you should reconsider your development setup if symlinking packages are the only way for you to develop your lib locally.