Webpack 4: Cannot resolve dependancy of symlinked module
See original GitHub issueHere’s a demo repo which replicates the issue being discussed:
https://bitbucket.org/omar-biblio/webpack-symlink-error-demo/src/master/
After upgrading from Webpack 1 to 4, I’ve encountered the following error:
Module not found: Error: Can't resolve 'react-dates/lib/utils/isInclusivelyAfterDay' in '/path_to_my_local_app/node_modules/@my_symlinked_packages/base-accessibility-date-picker/lib/components'
@ ./node_modules/@my_symlinked_packages/base-accessibility-date-picker/lib/components/AcessibleDatePicker.component.js 32:29-83
@ ./node_modules/@my_symlinked_packages/base-accessibility-date-picker/lib/index.js
@ ./app/components/borrowing/holds/HoldsPauseDateSelect/HoldsPauseDateSelect.jsx
@ ./app/components/borrowing/holds/HoldsPauseDateSelect/index.js
@ ./app/components/borrowing/holds/PauseHoldWorkflowView/components/BasePauseHoldWorkflowView.jsx
@ ./app/components/borrowing/holds/PauseHoldWorkflowView/components/SinglePauseHoldWorkflowView.jsx
@ ./app/containers/ItemTransactionWorkflowContainer.jsx
@ ./app/containers/WorkflowContainer.jsx
@ ./app/components/widgets/ItemWidget/ItemWidget.jsx
@ ./app/components/widgets/ItemWidget/index.js
@ ./app/containers/widgets/ItemWidgetContainer.jsx
@ ./app/routes/Routes.jsx
@ ./app/bootstrap.js
@ multi webpack-dev-server/client?http://localhost:3002 webpack/hot/only-dev-server ./app/bootstrap.js
I believe this error is indicating that Wepback 4 cannot resolve react-dates module which is a dependancy of a module that I am symlinking.
Here’s a sample of my project layout:
my_symlinked_packages
|-node_modules
|-package.json
|-src
|-my_lerna_package1
|-lib
|-specs
|-src
|-package.json (contains react-dates as a dependancy)
consuming_application
|-node_modules
|-@my_symlinked_packages
|-my_lerna_package1
|-package.json
|-webpack.config.js
|-app
Here’s an example of my webpack.config.js (it’s being composed of several js imports)
//import dependancies
//assign value to custom variables
module.exports = {
devtool: 'eval',
context: '/path_to_my_local_app',
mode: 'development',
entry:
{ app:
[ 'webpack-dev-server/client?http://localhost:3002',
'webpack/hot/only-dev-server',
'./app/bootstrap.js' ],
vendors:
[ 'raf/polyfill',
'babel-polyfill',
'immutable',
'iso',
'jquery',
'lodash',
'moment',
'react',
'react-router',
'redux',
'react-redux',
'superagent',
'when',
'rxjs',
'handlebars' ] },
externals: [ 'farmhash' ],
output:
{ path: '/path_to_my_local_app/public',
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: 'http://localhost:3002/' },
module:
{ rules:
[ {
use: ['react-hot-loader/webpack', 'happypack/loader?id=babel'],
test: /\.jsx?$/,
exclude: /node_modules/,
include: /app|server|node_modules\/@my_symlinked_packages/
},
{
test: /\.jsx?$/,
loader: 'eslint-loader',
exclude: /node_modules/,
include: /app|server/
},
{
test: /\.s?css$/,
use: [
'style-loader',
{
loader:'css-loader',
options: {
importLoaders: 2,
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: { sourceMap: true, config: { path: postcssConfig } }
},
{
loader: 'sass-loader',
options: {
outputStyle: 'expanded',
sourceMap: true
}
}]
},
{
test: /\.(png|jpg|gif|ico|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=' + inlinedAssetSizeLimit
},
{
test: require.resolve('jquery'),
loader: 'expose-loader?$!expose-loader?jQuery'
},
{
test: /handlebars\.js/,
loader: 'expose-loader?Handlebars'
} ] },
resolve:
{ symlinks: false,
modules:
[ '/path_to_my_local_app/app',
'/path_to_my_local_app/node_modules',
'/path_to_my_local_app/vendor' ],
alias:
{ handlebars: 'handlebars/dist/handlebars.js',
containers: '/path_to_my_local_app/app/containers',
constants: '/path_to_my_local_app/app/constants',
actions: '/path_to_my_local_app/app/actions' },
extensions: [ '.js', '.jsx' ] },
plugins: [ // hot reload
new HappyPack({
id: 'babel',
threads: 4,
loaders: [
{
loader: 'babel-loader',
query: {
cacheDirectory: true
}
}
]
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
__CLIENT__: true,
__SERVER__: false,
__DEVELOPMENT__: true,
__DISABLE_SSR__: false
}),
new webpack.LoaderOptionsPlugin({
options: {
sassLoader: {
data: `$is-widget: ${widgetBuild ? 'true' : 'false'};`
},
eslint: {
emitWarning: true
},
progress: true
}
}),
// https://github.com/halt-hammerzeit/webpack-isomorphic-tools
new WebpackIsomorphicToolsPlugin(webpackIsomorphicToolsConfig).development()
]
}
And here is a snippet of my postcss.config.js
module.exports = {
plugins: {
autoprefixer: {
browsers: ['last 2 version', 'ie >= 9', 'iOS >= 8']
}
}
};
Any help would be welcome!
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Webpack 4: Cannot resolve dependancy of symlinked module
I believe this error is indicating that Wepback 4 cannot resolve react-dates module which is a dependancy of a module that I am...
Read more >Resolve | webpack
Configure how modules are resolved. For example, when calling import 'lodash' in ES2015, the resolve options can change where webpack goes to look...
Read more >Chrysanthium // Load symlinked dependencies with webpack
Sometimes you need to use a specific webpack loader for a dependency which is only available locally as a symlink via npm link...
Read more >next-transpile-modules - npm
The way to fix it is easy, and it is what you should always do: install your dependencies with npm ci ("clean install")...
Read more >The magic behind npm link - Medium
Look for the module in the ./node_modules directory. If it is not there, recursively search in the parent directories' ./node_modules until either the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For
resolve.symlinks: true
or default: The dependency must be able to be resolved from the real location of the symlinked file.For
resolve.symlinks: false
: The dependency must be able to be resolved from the linked location of the symlinked file.We were able to solve this issue by adding a resolve path pointing to the nodule modules of the symlinked directory.