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

Webpack dependencies fail with npm linked package. #811

Closed
trusktr opened this Issue Feb 20, 2015 · 22 comments

Comments

Projects
None yet
@trusktr
Copy link

trusktr commented Feb 20, 2015

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
@trusktr

This comment has been minimized.

Copy link

trusktr commented Feb 20, 2015

100% certain these errors happen only after I've npm linked that package in the project.

@trusktr

This comment has been minimized.

Copy link

trusktr commented Feb 20, 2015

Any info I can provide? I can't really provide access to the repo I'm linking because it's internal/private, but maybe there's some useful specific info I can provide?

@sokra

This comment has been minimized.

@trusktr

This comment has been minimized.

Copy link

trusktr commented Feb 22, 2015

Ah, ok. Thanks!! I would've had no idea!

@trusktr

This comment has been minimized.

Copy link

trusktr commented Jul 3, 2016

@sokra This problem isn't intuitive at all. For example, it just happened to me again: krasimir/cssx#15. I think a solution is needed.

@trusktr trusktr reopened this Jul 3, 2016

@sokra

This comment has been minimized.

Copy link
Member

sokra commented Sep 7, 2016

for loaders the behavior was changed to webpack 2. They now resolve relative to the configuration file instead of relative to the affected module

@sokra

This comment has been minimized.

Copy link
Member

sokra commented Sep 7, 2016

also related #2937

@SpaceK33z

This comment has been minimized.

Copy link
Member

SpaceK33z commented Dec 24, 2016

Closing this since it appears to have been fixed in webpack 2. @trusktr, if you still have this issue in webpack 2, please re-open.

@MatteoWebDesigner

This comment has been minimized.

Copy link

MatteoWebDesigner commented Feb 27, 2017

Hi I am using webpack 2 and I cannot figure out why I am having this issue:

ERROR in ./src/index.js
Module not found: Error: Can't resolve 'webpack-test-import' in '/user/test-webpack/src'
@ ./src/index.js 7:25-55
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./index.js

here the webpack config

import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';

export default {
    context: path.resolve(__dirname, 'src'),
    entry: './index.js',
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: 'bundle.js',
        chunkFilename: 'bundle-[id].js'
    },
    module: {
        rules: [{
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader',
                options: {
                    cacheDirectory: 'cache/'
                }
            }
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html',
            minify: {
                collapseWhitespace: true
            }
        }),
    ],
    devtool: "cheap-eval-source-map",
    devServer: {
        contentBase: path.join(__dirname, "build"),
        compress: true,
        port: 8080,
        open: true
    }
};

index.js

import internalModule from './module.js';
import externalModule from 'webpack-test-import';

console.log('internal import, ' + internalModule);
@septagram

This comment has been minimized.

Copy link

septagram commented May 31, 2017

@SpaceK33z no it's not fixed, having the same problem here.

ERROR in ../react-calendar-component/lib/Calendar.js
Module not found: Error: Can't resolve 'react' in 'd:\Dropbox\Code\react-calendar-component\lib'

Worse yet, the workaround doesn't work anymore:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.resolve has an unknown property 'fallback'. These properties are valid:
   object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
 - configuration.resolveLoader has an unknown property 'fallback'. These properties are valid:
   object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
@damianobarbati

This comment has been minimized.

Copy link

damianobarbati commented Jun 3, 2017

Same here with webpack 2.x, npm-link'ed modules hangs compilation...

@miketeix

This comment has been minimized.

Copy link

miketeix commented Jun 13, 2017

Same here with webpack 2.x, using yarn link in my case

@erquhart

This comment has been minimized.

Copy link

erquhart commented Jun 20, 2017

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.

@thescientist13

This comment has been minimized.

Copy link

thescientist13 commented Jun 21, 2017

thanks @erquhart , that helped resolve the issue for me!

@joaoreynolds

This comment has been minimized.

Copy link

joaoreynolds commented Jul 25, 2017

Turning off symlink resolution also makes it so webpack can't watch for changes in the linked dependency :( Any other solutions?

@mesqueeb

This comment has been minimized.

Copy link

mesqueeb commented Jun 30, 2018

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?

@yuvke

This comment has been minimized.

Copy link

yuvke commented Jul 16, 2018

@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 the modules array.

For example something like this:

const path = require('path');
const projectPath = 'full/path/to/project'
const projectNodeModulesPath = path.resolve(projectPath, 'node_modules');
const modules = [ projectNodeModulesPath ];
    
await Promise.all((await fse.readdir(projectNodeModulesPath)).map(async el => {
    const modulePath = path.resolve(projectNodeModulesPath, el);
    if ((await fse.lstat(modulePath)).isSymbolicLink()) {
        const realModulePath = path.resolve(await fse.realpath(modulePath), 'node_modules');
        resolves.push(realModulePath);
    }
}));
@mesqueeb

This comment has been minimized.

Copy link

mesqueeb commented Jul 17, 2018

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?

@diachedelic

This comment has been minimized.

Copy link

diachedelic commented Sep 26, 2018

I adapted @yuvke 's solution, making it sync and supporting scoped packages. See this gist for a webpack config example.

@chovy

This comment has been minimized.

Copy link

chovy commented Jan 10, 2019

@diachedelic that doesn't work for me, same error.

@diachedelic

This comment has been minimized.

Copy link

diachedelic commented Jan 12, 2019

@chovy could you try printing the results of findLinkedModules to console, and comparing it with the pathname in the error message?

@chovy

This comment has been minimized.

Copy link

chovy commented Jan 12, 2019

i goofed. i didn't know i had to build the library first. now it works fine w/o any changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment