Angular:5.0.1 / 角度CLI:1.5.0 / 节点:8.9.1 / npm:5.5.1 / Os:win32 x64
执行" npm start"时出现以下错误在终端/命令提示符下。谁能帮我解决这个问题?我花了一整天的时间试图修复它而没有运气。
这是我的package.json
的脚本部分"scripts": {
"start": "webpack-dev-server --inline --progress --port 8080"
},
webpack.config.js
module.exports = require('./config/webpack.dev.js');
webpack.common.js
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/main.ts'
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
options: { configFileName: helpers.root('src', 'tsconfig.json') }
} , 'angular2-template-loader'
]
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-loader?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract({ fallbackLoader: 'style-loader', loader: 'css-loader?sourceMap' })
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw-loader'
}
]
},
plugins: [
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)@angular/,
helpers.root('./src'), // location of your src
{} // a map of your routes
),
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
})
]
};
webpack.dev.js
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
module.exports = webpackMerge(commonConfig, {
devtool: 'cheap-module-eval-source-map',
output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
plugins: [
new ExtractTextPlugin('[name].css')
],
devServer: {
historyApiFallback: true,
stats: 'minimal'
}
});
webpack.prod.js
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
module.exports = webpackMerge(commonConfig, {
devtool: 'source-map',
output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
mangle: {
keep_fnames: true
}
}),
new ExtractTextPlugin('[name].[hash].css'),
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
}),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: false // workaround for ng2
}
})
]
});
这是错误
0信息如果以ok 1 verbose cli [' C:\ Program Files \ nodejs \ node.exe',1详细cli' C:\ Program Files \ nodejs \ node_modules \ npm \ bin \ npm-cli.js',1详细cli
'启动' ] 2信息使用npm@5.5.1 3信息使用node@v8.9.1 4详细 run-script [' prestart',' start',' poststart' ] 5信息生命周期 angular-io-example@1.0.0~prestart:angular-io-example@1.0.0 6 info 生命周期angular-io-example@1.0.0~start:angular-io-example@1.0.0 7 verbose lifecycle angular-io-example@1.0.0 ~start:unsafe-perm in lifecycle true 8详细生命周期angular-io-example@1.0.0~start: 路径:C:\ Program 文件\的NodeJS \ node_modules \ NPM \ BIN \节点-GYP槽; C:\ Users \用户cbonsu \下载\ sample_pro \的WebPack \ node_modules.bin; C:\窗口\ system32; C:\ WINDOWS; C:\ Windows \ SYSTEM32 \ WBEM; C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \; C:\ PROGRAM Files \ Microsoft SQL Server \ 130 \ Tools \ Binn \; C:\ Program Files \ Git \ cmd; C:\ Program Files(x86)\ Microsoft SQL Server \ 130 \ Tools \ Binn \; C:\ Program Files(x86)\ Microsoft SQL Server \ 130 \ DTS \ Binn \; C:\ Program Files \ Microsoft SQL Server \ 130 \ DTS \ Binn \; C:\ Program Files \ Microsoft SQL Server \ Client SDK \ ODBC \ 130 \ Tools \ Binn \; C:\ Program Files(x86)\ Microsoft SQL Server \ Client SDK \ ODBC \ 130 \ Tools \ Binn \; C:\ Program Files (x86)\ Microsoft SQL 服务器\ 130个\ TOOLS \ BINN \ ManagementStudio \; C:\ WINDOWS \ system32 \设置\ systemprofile.dnx \ BIN; C:\ PROGRAM Files \ Microsoft DNX \ Dnvm \; C:\ Program Files \ Microsoft \ Web Platform Installer \; C:\ Program Files \ dotnet \; C:\ Program 文件\的NodeJS \; C:\用户\ cbonsu \应用程序数据\本地\微软\ WindowsApps; C:\ PROGRAM Files \ nodejs; C:\ Program Files \ Microsoft VS. Code \ bin; C:\ Users \ cbonsu \ AppData \ Roaming \ npm 9详细生命周期 angular-io-example@1.0.0 ~start:CWD: C:\ Users \ cbonsu \ Downloads \ sample_pro \ webpack 10愚蠢的生命周期 angular-io-example@1.0.0~start:Args:[' / d / s / c',10傻生命周期 ' webpack-dev-server --inline --progress --port 8080' ] 11傻 lifecycle angular-io-example@1.0.0 ~start:返回:代码:1信号: null 12 info lifecycle angular-io-example@1.0.0~start:执行失败 start script 13 verbose stack错误:angular-io-example@1.0.0 start:webpack-dev-server --inline --progress --port 8080
13详细堆栈 在EventEmitter处退出状态1 13详细堆栈。 (C:\ PROGRAM 文件\的NodeJS \ node_modules \ NPM \ node_modules \ NPM-生命周期\ index.js:280:16) 在emitTwo上的13个详细堆栈(events.js:126:13)13详细堆栈
在EventEmitter.emit(events.js:214:7)13详细堆栈at 子进程。 (C:\ PROGRAM 文件\的NodeJS \ node_modules \故宫\ node_modules \ NPM-生命周期\ LIB \ spawn.js:55:14) 在emitTwo上的13个详细堆栈(events.js:126:13)13详细堆栈
在ChildProcess.emit(events.js:214:7)13详细堆栈at maybeClose(internal / child_process.js:925:16)13详细堆栈at Process.ChildProcess._handle.onexit(internal / child_process.js:209:5) 14 verbose pkgid angular-io-example@1.0.0 15 verbose cwd C:\ Users \ cbonsu \ Downloads \ sample_pro \ webpack 16详细的Windows_NT 10.0.15063 17 verbose argv" C:\ Program Files \ nodejs \ node.exe" " C:\ Program Files \ nodejs \ node_modules \ npm \ bin \ npm-cli.js" "开始" 18详细节点v8.9.1 19详细npm v5.5.1 20错误代码 ELIFECYCLE 21错误错误1 22错误angular-io-example@1.0.0 start:webpack-dev-server --inline --progress --port 8080
22错误退出 status 1 23 error在angular-io-example@1.0.0启动脚本中失败。 23错误这可能不是npm的问题。有可能 上面的额外日志输出。 24详细退出[1,true]
答案 0 :(得分:1)
它应该成功
npm cache clean
npm install
npm start
答案 1 :(得分:0)
我发现了一种更简单的方法。放弃" npm start"和webpack方法一起使用angular-cli。使用angular-cli,调用" ng build --prod"处理一切(等等)。在幕后,它使用webpack,但它处理所有涉及的复杂问题,因此开发人员不必这样做。
答案 2 :(得分:0)
我只是通过验证和清除缓存,然后将npm更新为最新版本,解决了这个问题。
npm cache verify
npm install
npm start
答案 3 :(得分:0)
如果npm clean cache --force
npm install
npm start
对您不起作用。尝试重命名根文件夹。这对我来说非常有用。