我想npm鏈接一個模塊使用webpack作爲其捆綁程序的項目。當然,嘗試很多事情之後,我不斷收到此錯誤:npm鏈接與webpack - 找不到模塊
ERROR in ./src/components/store/TableView.jsx
Module not found: Error: Cannot resolve module 'react-bootstrap-table'
下面是這樣做時,我採取的具體步驟:
1.) cd ../forks/react-bootstrap-table
2.) npm link
(success, checked ~/.nvm/.../node_modules/react-bootstrap-table for symlink and it's there)
3.) cd ../../projRoot/
4.) npm link react-bootstrap-table
(no errors thrown?, says successful link)
5.) node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js
解決方案我已經試過:
- https://webpack.github.io/docs/troubleshooting.html
- How to make a linked component peerDepdencies use the equivalent node_modules of the script being linked to?
- 而在谷歌許多紫色的鏈接SERP中
webpack.config.js
const webpack = require('webpack')
const path = require('path')
const ROOT_PATH = path.resolve(__dirname)
module.exports = {
devtool: process.env.NODE_ENV === 'production' ? '' : 'source-map',
entry: [
'webpack/hot/only-dev-server',
'./src/index.js'
],
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['react-hot','babel']
},
{
test: /\.scss$/,
loaders: ['style','css','sass'],
exclude: /node_modules/
},
{
test: /\.css$/,
loaders: ['style','css']
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file-loader'
}
]
},
resolve: {
extensions: ['', '.js', '.jsx'],
fallback: path.resolve(__dirname, './node_modules')
},
resolveLoader: {
fallback: path.resolve(__dirname, './node_modules')
},
output: {
path: process.env.NODE_ENV === 'production' ? path.resolve(ROOT_PATH, 'app/dist') : path.resolve(ROOT_PATH, 'app/build'),
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: path.resolve(ROOT_PATH),
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
stats: 'errors-only',
host: '192.168.1.115'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
}
注:
1.這是該項目的唯一符號鏈接
2.我跑故宮內安裝分叉版本(也試過沒有,沒有按」 t工作)
3.我使用NVM,但我沒有成功使用webpack之前使用了符號鏈接。
我已經在這裏住了幾天了,任何幫助將不勝感激。
我也是。堅果沒有現有的答案被發現。問題是顯而易見的 - babel/webpack不遵循或容納符號鏈接 – Tim
這對我來說是一種顯示屏。我爲我的應用程序與我的應用程序一起開發了多個支持庫,看起來我需要找到webpack的替代方案來支持此工作流程。 – Matt
有趣的事實:webpack **不支持npm鏈接。這是「有據可查的」,但@#$ *(很難找到。https://webpack.github.io/docs/troubleshooting.html#npm-linked-modules-doesn-t-find-their-dependencies。我們已經經常碰到這個問題,我們總是停止使用npm鏈接:如果你有一個fork,或者指向'require('../../../ yourfork')''儘可能多的'../',因爲您需要到達fork目錄,或者,使用github鏈接而不是npm semver指向自己的fork,或者(並且我們已經開始執行此操作)只是將您的fork複製到node_modules dir中開發工作。 –