当前行为是什么?
当同时使用cli
和webpack
函数调用webpack时,Webpack返回下面提供的错误。奇怪的是,它在重新安装节点模块后开始返回此错误。
如果当前行为是错误,请提供重现步骤。:
webpack --config=./configs/webpack.config.lib.js
throw new TypeError('"string" must be a string, Buffer, or ArrayBuffer');
^
TypeError: "string" must be a string, Buffer, or ArrayBuffer
at Function.byteLength (buffer.js:481:11)
at RawSource.size (Documents/GitHub/projectName/node_modules/webpack-sources/lib/Source.js:18:17)
at obj.assets.compilationAssets.map (Documents/GitHub/projectName/node_modules/webpack/lib/Stats.js:415:20)
at Array.map (<anonymous>)
at Stats.toJson (Documents/GitHub/projectName/node_modules/webpack/lib/Stats.js:412:6)
at Stats.toString (Documents/GitHub/projectName/node_modules/webpack/lib/Stats.js:857:20)
at compilerCallback (Documents/GitHub/projectName/node_modules/webpack-cli/bin/cli.js:333:32)
at compiler.run (Documents/GitHub/projectName/node_modules/webpack-cli/bin/cli.js:359:7)
at finalCallback (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:257:39)
at hooks.done.callAsync.err (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:306:14)
at AsyncSeriesHook.eval [as callAsync] (eval at create (Documents/GitHub/projectName/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (Documents/GitHub/projectName/node_modules/tapable/lib/Hook.js:154:20)
at emitRecords.err (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:304:22)
at Compiler.emitRecords (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:499:39)
at emitAssets.err (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:298:10)
at hooks.afterEmit.callAsync.err (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:485:14)
at _err0 (eval at create (Documents/GitHub/projectName/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
at callback (Documents/GitHub/projectName/node_modules/copy-webpack-plugin/dist/index.js:126:17)
at afterEmit (Documents/GitHub/projectName/node_modules/copy-webpack-plugin/dist/index.js:220:13)
at AsyncSeriesHook.eval [as callAsync] (eval at create (Documents/GitHub/projectName/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
at AsyncSeriesHook.lazyCompileHook (Documents/GitHub/projectName/node_modules/tapable/lib/Hook.js:154:20)
at asyncLib.forEachLimit.err (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:482:27)
at Documents/GitHub/projectName/node_modules/neo-async/async.js:2818:7
at done (Documents/GitHub/projectName/node_modules/neo-async/async.js:3522:9)
at AsyncSeriesHook.eval [as callAsync] (eval at create (Documents/GitHub/projectName/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at outputFileSystem.writeFile.err (Documents/GitHub/projectName/node_modules/webpack/lib/Compiler.js:464:33)
at Documents/GitHub/projectName/node_modules/graceful-fs/graceful-fs.js:57:14
at FSReqWrap.oncomplete (fs.js:135:15)
Webpack配置?
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const packageJSON = require('./package.json');
const srcPath = path.resolve(__dirname, '../src');
const dstPath = path.join(__dirname, '../out/publish');
const buildMode = process.env.NODE_ENV || 'development';
module.exports = {
target: 'node',
context: srcPath,
entry: {
main: [ `${srcPath}/index.ts` ]
},
output: {
path: path.join(__dirname, '../out/publish'),
filename: '[name].js',
chunkFilename: '[name].js',
libraryTarget: 'commonjs2',
library: packageJSON.name
},
mode: buildMode,
// devtool: buildMode === 'development' ? 'source-map' : '',
externals: {
'big.js': true,
'classnames': true,
'lodash': true,
'moment': true,
'prop-types': true,
'react': true,
'react-dom': true,
'react-motion': true,
'react-transition-group': true
},
resolve: {
modules: [ srcPath, 'node_modules' ],
extensions: [ '.ts', '.tsx', '.js', '.css' ],
mainFields: [ 'main', 'browser', 'module' ]
},
module: {
rules: [
{
test: /\.(woff2?|ttf|svg|jpg|gif|png|eot)$/,
use: [ {
loader: 'url-loader',
options: {
limit: 64000
}
} ]
},
{
test: /\.tsx?$/,
loader: `ts-loader?configFile=${path.join(__dirname, 'tsconfig.lib.json')}`,
exclude: /node_modules/
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
'typed-css-modules-loader',
'sass-loader'
],
},
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"production"',
'DEBUG': 'window.envDEBUG'
},
__DEV__: false
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'package.json'),
to: `${dstPath}/package.json`
},
{
from: `${srcPath}/core/styles/variables.scss`,
to: `${dstPath}/variables.scss`
},
{
from: path.join(__dirname, '../README.md'),
to: `${dstPath}/README.md`
},
{
from: path.join(__dirname, '../CHANGELOG.md'),
to: `${dstPath}/CHANGELOG.md`
},
]),
new webpack.optimize.OccurrenceOrderPlugin(),
new ExtractTextPlugin(`./ui-library.css`)
],
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
beautify: false,
comments: false,
sourceMap: true,
compress: {
sequences: true,
booleans: true,
loops: true,
unused: true,
warnings: false,
drop_console: true,
unsafe: true
}
}
}),
]
}
};
其他相关信息:
4.41.0
也出现3.12.0
,在
3.11.0
dubnium -> v10.17.0
MACOS 10.14.2 (18C54)