[英]Webpack not bundling .json file in node_modules properly
I am currently building an electron app to deploy on a raspberry pi3 with a react front end. 我目前正在构建一个电子应用程序,以部署在具有反应前端的树莓派pi3上。 It's using webpack to bundle everything. 它使用webpack捆绑所有内容。 I am also trying to use the node-raspicam package to interact with the camera module. 我还尝试使用node-raspicam包与相机模块进行交互。 I have successfully been able to use the node-raspbicam package on it's own outside of this app. 我已经能够成功在此应用程序外部使用node-raspbicam程序包。 But when I try to import it in this application I get the following error Module not found: Error: Cannot resolve 'file' or 'directory' ../options in /usr/src/app/node_modules/raspicam/lib @ ./~/raspicam/lib/raspicam.js 7:17-38 8:12-33
但是,当我尝试将其导入此应用程序时,出现以下错误, Module not found: Error: Cannot resolve 'file' or 'directory' ../options in /usr/src/app/node_modules/raspicam/lib @ ./~/raspicam/lib/raspicam.js 7:17-38 8:12-33
in raspicam.js it tries to do parameters = require("../options").parameters
which is where it is failing. 在raspicam.js中,它尝试执行的parameters = require("../options").parameters
失败了。 In the raspicam tree within node_modules options.json exists one directory up from where it is being called. 在node_modules options.json中的raspicam树中,从调用它的位置开始存在一个目录。
My thought is webpack is not bundling this json file properly therefore, it cannot be found. 我的想法是webpack无法正确捆绑此json文件,因此无法找到它。
My webpack loaders : 我的webpack加载器:
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.(jpg|png)$/,
loader: 'file?name=[path][name].[hash].[ext]',
include: path.images
},
{
test: /\.json$/,
loader: 'json-loader'
}]
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['', '.js', '.jsx'],
packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
},
plugins: [
],
externals: [
// put your node 3rd party libraries which can't be built with webpack here
// (mysql, mongodb, and so on..)
]
I am still fairly new to webpack. 我对webpack还是很陌生。 What am I missing so that the options.json file in the raspicam node_module gets bundled properly? 我缺少什么,因此raspicam node_module中的options.json文件正确捆绑了?
Try adding .json
to the extensions
in the resolve
object in the config file. 尝试将.json
添加到配置文件中resolve
对象的extensions
中。 It may work. 它可能会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.