我正在开发一个必须准备就绪的项目,但是由于下载依赖性,我的webpack(我用于其他几个项目)无法正常工作。我需要帮助。
这是我的package.json文件:
{
"name": "beanworks",
"version": "1.0.0",
"description": "accounts payable app",
"main": "index.js",
"repository": {
"type": "github",
"url": "https://github.com/xumes/beanworks-accounts-payable"
},
"scripts": {
"test": "standard",
"client": "webpack -w --config webpack.config.js",
"server": "nodemon index.js",
"dev": "concurrently --kill-others-on-fail \"npm run client\" \"npm run server\"",
"start": "node index.js",
"beforeInstall": "webpack --config webpack.config.prod.js"
},
"keywords": [
"beanworks",
"xero",
"invoice",
"node.js",
"react.js",
"webpack"
],
"author": "Reginaldo Santos (reginaldosantos.br@gmail.com)",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"babel-runtime": "^6.26.0",
"body-parser": "^1.18.3",
"clean-webpack-plugin": "^0.1.19",
"cookie-parser": "^1.4.3",
"cors": "^2.8.5",
"express": "^4.16.3",
"express-session": "^1.15.6",
"html-webpack-plugin": "^3.2.0",
"lodash": "^4.17.11",
"react": "^16.4.1",
"react-data-export": "^0.5.0",
"react-dom": "^16.4.1",
"react-redux": "^5.1.1",
"react-router-dom": "^4.3.1",
"redux": "^4.0.1",
"redux-promise": "^0.6.0",
"session-memory-store": "^0.2.2",
"socket.io": "^2.1.1",
"socket.io-client": "^2.1.1",
"xero-node": "^3.0.16"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"concurrently": "^3.6.0",
"css-loader": "^0.28.11",
"file-loader": "^1.1.11",
"nodemon": "^1.17.5",
"standard": "^12.0.1",
"style-loader": "^0.21.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.12.2",
"webpack-cli": "^3.0.8",
"webpack-merge": "^4.1.3"
},
"engines": {
"node": "8.11.3"
}
}
这是webpack.common.js:
const path = require('path')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const cleanOptions = {
verbose: true,
dry: false
}
const APP_DIR = path.resolve(__dirname, './src/client')
module.exports = {
entry: `${APP_DIR}/index.js`,
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(jsx|js)?$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
],
exclude: [/node_modules/]
},
{
test: /(\.css|.scss)$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'sass-loader' }
],
exclude: [/node_modules/]
},
{
test: /\.(eot|woff|woff2|svg|ttf|jpg)$/,
loader: 'file-loader',
exclude: [/node_modules/]
}
]
},
plugins: [
new CleanWebpackPlugin(path.resolve(__dirname, 'dist'), cleanOptions),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'config/index.html')
})
]
}
webpack.config.prod.js,但该错误发生在上面的commong文件中。
const webpack = require('webpack')
const merge = require('webpack-merge')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const common = require('./webpack.common.js')
module.exports = merge(common, {
mode: 'production',
stats: {
colors: false,
hash: true,
timings: true,
assets: true,
chunks: true,
chunkModules: true,
modules: true,
children: true
},
optimization: {
minimizer: [
new UglifyJSPlugin({
sourceMap: true,
uglifyOptions: {
compress: {
inline: false
}
}
})
],
runtimeChunk: false,
splitChunks: {
cacheGroups: {
default: false,
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor_app',
chunks: 'all',
minChunks: 2
}
}
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
})
这是我收到错误的输出:
reginaldosantos$ npm run beforeInstall
> beanworks@1.0.0 beforeInstall /Users/reginaldosantos/dev/lab/
> webpack --config webpack.config.prod.js
clean-webpack-plugin: /Users/reginaldosantos/dev/lab/dist has been removed.
Hash: e12ecfae20b56e678e04
Version: webpack 4.28.2
Time: 27814ms
Built at: 12/26/2018 10:40:55 AM
3 assets
Entrypoint main = bundle.js
chunk {0} bundle.js (main) 2.1 MiB [entry] [rendered]
[10] (webpack)/buildin/global.js 472 bytes {0} [built]
[28] ./node_modules/react-redux/es/index.js + 19 modules 36.2 KiB {0} [built]
| 20 modules
[64] ./src/client/actions/index.js 526 bytes {0} [built]
[122] ./src/client/index.js 1010 bytes {0} [built]
[131] (webpack)/buildin/harmony-module.js 573 bytes {0} [built]
[146] ./src/client/containers/Refresh.js 4.17 KiB {0} [built]
[167] ./src/client/images/vendors.jpg 82 bytes {0} [built]
[168] ./src/client/images/accts.jpg 82 bytes {0} [built]
[169] ./src/client/containers/Vendors.js 6.75 KiB {0} [built]
[176] (webpack)/buildin/amd-define.js 85 bytes {0} [built]
[177] (webpack)/buildin/amd-options.js 80 bytes {0} [built]
[289] ./src/client/containers/Accounts.js 7.17 KiB {0} [built]
[291] ./src/client/reducers/index.js 433 bytes {0} [built]
[292] ./src/client/reducers/reducer_xero.js 479 bytes {0} [built]
[293] ./node_modules/react-router-dom/es/index.js + 34 modules 80.3 KiB {0} [built]
| 35 modules
+ 279 hidden modules
[10] (webpack)/buildin/global.js 472 bytes {0} [built]
[28] ./node_modules/react-redux/es/index.js + 19 modules 36.2 KiB {0} [built]
| 20 modules
[64] ./src/client/actions/index.js 526 bytes {0} [built]
[122] ./src/client/index.js 1010 bytes {0} [built]
[131] (webpack)/buildin/harmony-module.js 573 bytes {0} [built]
[146] ./src/client/containers/Refresh.js 4.17 KiB {0} [built]
[167] ./src/client/images/vendors.jpg 82 bytes {0} [built]
[168] ./src/client/images/accts.jpg 82 bytes {0} [built]
[169] ./src/client/containers/Vendors.js 6.75 KiB {0} [built]
[176] (webpack)/buildin/amd-define.js 85 bytes {0} [built]
[177] (webpack)/buildin/amd-options.js 80 bytes {0} [built]
[289] ./src/client/containers/Accounts.js 7.17 KiB {0} [built]
[291] ./src/client/reducers/index.js 433 bytes {0} [built]
[292] ./src/client/reducers/reducer_xero.js 479 bytes {0} [built]
[293] ./node_modules/react-router-dom/es/index.js + 34 modules 80.3 KiB {0} [built]
| 35 modules
+ 279 hidden modules
ERROR in ./node_modules/tempa-xlsx/ods.js
Module not found: Error: Can't resolve 'xlsx' in '/Users/reginaldosantos/dev/lab/node_modules/tempa- xlsx'
@ ./node_modules/tempa-xlsx/ods.js 13:21-41
@ ./node_modules/tempa-xlsx/xlsx.js
@ ./node_modules/react-data- export/dist/ExcelPlugin/components/ExcelFile.js
@ ./node_modules/react-data-export/dist/index.js
@ ./src/client/components/Download.js
@ ./src/client/components/App.js
@ ./src/client/index.js
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
chunk {0} index.html 530 KiB [entry] [rendered]
[0] ./node_modules/html-webpack- plugin/lib/loader.js!./config/index.html 2.29 KiB {0} [built]
[2] (webpack)/buildin/global.js 472 bytes {0} [built]
[3] (webpack)/buildin/module.js 497 bytes {0} [built]
+ 1 hidden module
[0] ./node_modules/html-webpack- plugin/lib/loader.js!./config/index.html 2.29 KiB {0} [built]
[2] (webpack)/buildin/global.js 472 bytes {0} [built]
[3] (webpack)/buildin/module.js 497 bytes {0} [built]
+ 1 hidden module
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! beanworks@1.0.0 beforeInstall: `webpack --config webpack.config.prod.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the beanworks@1.0.0 beforeInstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/reginaldosantos/.npm/_logs/2018-12- 26T12_40_55_827Z-debug.log
答案 0 :(得分:0)
好吧,我对此并不感到骄傲,但是我通过替换“下载到Excel”依赖项解决了该问题。 我使用的是 react-excel-workbook ,而不是 react-data-export 。 我的Webpack运行正常,正在生成用于生产的捆绑包。