Javascript 需要软件包会导致错误
每次绑定脚本时,都会出现以下错误:Javascript 需要软件包会导致错误,javascript,webpack,Javascript,Webpack,每次绑定脚本时,都会出现以下错误: ERROR in ./resources/assets/scripts/main.js Module not found: Error: Can't resolve 'datatables.net-colreorder-bs4' in '/home/vagrant/sites/laravel/resources/assets/scripts' @ ./resources/assets/scripts/main.js 12:23-63 我的网页包配置js:
ERROR in ./resources/assets/scripts/main.js
Module not found: Error: Can't resolve 'datatables.net-colreorder-bs4' in '/home/vagrant/sites/laravel/resources/assets/scripts'
@ ./resources/assets/scripts/main.js 12:23-63
我的网页包配置js:
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './resources/assets/scripts/main.js',
output: {
path: path.resolve(__dirname, './public/js'),
filename: 'mainBundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['env']
}
}
]
},
stats: {
colors: true
},
node: {
fs: 'empty'
},
devtool: 'source-map'
};
我的主js文件如下所示(没有其他模块引起任何问题)
我检查了路径,它是确定的,我也改变了绝对路径,但它没有任何效果
包json:
"dependencies": {
"add": "^2.0.6",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"chart.js": "^2.7.1",
"datatables.net-bs4": "^1.10.16",
"datatables.net-buttons-bs4": "^1.5.1",
"datatables.net-colreorder-bs4": "^1.4.1",
"datatables.net-responsive-bs4": "^2.2.1",
"gulp-changed": "^3.2.0",
"gulp-debug": "^3.2.0",
"jquery": "^3.2.1",
"jquery-ui": "^1.12.1",
"jszip": "^3.1.5",
这个问题仍然没有解决,因为某些原因,在使用npm时将找不到“datatables.net-colreorder-bs4”。。。我决定将其作为一个随时可用的捆绑包加载,而不是webpack…唯一可能缺少的是
解析
,但我不确定默认情况下webpack是否在node_模块中查找:
module.exports = {
entry: './resources/assets/scripts/main.js',
output: {
path: path.resolve(__dirname, './public/js'),
filename: 'mainBundle.js'
},
resolve: {
modules: [
resolve("./node_modules/")
]
},
如果是这种情况,则会很奇怪,因为找到了其他模块。要在客户端模式下使用pdfmake,您需要直接使用构建版本:
window.pdfMake = require('pdfmake/build/pdfmake.js');
var vfs = require('pdfmake/build/vfs_fonts.js');
window.pdfMake.vfs = vfs.pdfMake.vfs;
你是用npm安装的吗?什么是package.json?如果您安装了npm-S jszip pdfmake…或者如果您在package.json中有它们,那么它应该可以工作。您可以只安装npm。我确实使用npm安装了
window.pdfMake = require('pdfmake/build/pdfmake.js');
var vfs = require('pdfmake/build/vfs_fonts.js');
window.pdfMake.vfs = vfs.pdfMake.vfs;