Angular 无法执行启动脚本
角度:5.0.1/ Angular CLI:1.5.0/ 节点:8.9.1/ 净现值:5.5.1/ 操作系统:win32 x64 在终端/命令提示符中执行“npm start”时,我遇到以下错误。有人能帮我解决这个问题吗?我花了一整天的时间试图修好它,但运气不好 这是我的包的脚本部分。jsonAngular 无法执行启动脚本,angular,npm,webpack,Angular,Npm,Webpack,角度:5.0.1/ Angular CLI:1.5.0/ 节点:8.9.1/ 净现值:5.5.1/ 操作系统:win32 x64 在终端/命令提示符中执行“npm start”时,我遇到以下错误。有人能帮我解决这个问题吗?我花了一整天的时间试图修好它,但运气不好 这是我的包的脚本部分。json "scripts": { "start": "webpack-dev-server --inline --progress --port 8080" }, webpack.config.js
"scripts": {
"start": "webpack-dev-server --inline --progress --port 8080"
},
webpack.config.js
module.exports = require('./config/webpack.dev.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'
})
]
};
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'
}
});
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
}
})
]
});
webpack.common.js
module.exports = require('./config/webpack.dev.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'
})
]
};
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'
}
});
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
}
})
]
});
webpack.dev.js
module.exports = require('./config/webpack.dev.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'
})
]
};
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'
}
});
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
}
})
]
});
webpack.prod.js
module.exports = require('./config/webpack.dev.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'
})
]
};
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'
}
});
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详细cli['C:\Program
Files\nodejs\node.exe',1 verbose cli'C:\Program
Files\nodejs\node\u modules\npm\bin\npm cli.js',1个详细cli使用“开始”]2信息npm@5.5.13信息使用node@v8.9.14冗长的 运行脚本['prestart','start','poststart']5信息生命周期 角度io-example@1.0.0~prestart:angular-io-example@1.0.06信息 生命周期角度io-example@1.0.0~start:angular io-example@1.0.07. 详细生命周期角度io-example@1.0.0~start:不安全烫发 lifecycle true 8详细生命周期角度io-example@1.0.0~start: 路径:C:\程序 文件\nodejs\node\u模块\npm\bin\node-gyp-bin;C:\Users\cbonsu\Downloads\sample\u pro\webpack\node\u modules.bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\程序 文件\Microsoft SQL Server\130\Tools\Binn\;C:\程序 文件\Git\cmd;C:\ProgramFiles(x86)\Microsoft SQL 服务器\130\Tools\Binn\;C:\ProgramFiles(x86)\Microsoft SQL 服务器\130\DTS\Binn\;C:\Program Files\Microsoft SQL 服务器\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\ProgramFiles(x86)\Microsoft SQL 服务器\客户端SDK\ODBC\130\Tools\Binn\;C:\程序文件 (x86)\Microsoft SQL 服务器\130\Tools\Binn\ManagementStudio\;C:\WINDOWS\system32\config\systemprofile.dnx\bin;C:\程序 文件\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft\Web平台 安装程序\;C:\ProgramFiles\dotnet\;C:\程序 文件\nodejs\;C:\Users\cbonsu\AppData\Local\Microsoft\WindowsApps;C:\程序 文件\节点;C:\Program Files\Microsoft VS 代码\bin;C:\Users\cbonsu\AppData\Roaming\npm 9详细生命周期 角度io-example@1.0.0~start:CWD: C:\Users\cbonsu\Downloads\sample\u pro\webpack 10 角度io-example@1.0.0~start:Args:['/d/s/c',10个字符 '网页包开发服务器--内联--进度--端口8080']11 生命周期角度io-example@1.0.0~start:返回:代码:1信号: 空12信息生命周期角io-example@1.0.0~start:执行失败 启动脚本13详细堆栈错误:角度io-example@1.0.0开始:
webpack开发服务器--内联--进度--端口8080
13详细堆栈
在EventEmitter处退出状态1 13详细堆栈。
(C:\方案
Files\nodejs\node\u modules\npm\node\u modules\npm lifecycle\index.js:280:16)
在emitTwo(events.js:126:13)处的13个详细堆栈13个详细堆栈在EventEmitter.emit(events.js:214:7)13详细堆栈 儿童过程。(C:\方案 Files\nodejs\node\u modules\npm\node\u modules\npm lifecycle\lib\spawn.js:55:14) 在emitTwo(events.js:126:13)处的13个详细堆栈13个详细堆栈
在ChildProcess.emit(events.js:214:7)13详细堆栈 maybeClose(internal/child_process.js:925:16)13详细堆栈位于 Process.ChildProcess._handle.onexit(内部/child_Process.js:209:5) 14详细pkgid角度io-example@1.0.015详细cwd C:\Users\cbonsu\Downloads\sample\u pro\webpack 16详细Windows\u NT 10.0.15063 17详细argv“C:\Program Files\nodejs\node.exe”“C:\Program Files\nodejs\node\u modules\npm\bin\npm cli.js” “开始”18详细节点v8.9.1 19详细npm v5.5.1 20错误代码 ELIFECYCLE 21错误错误1错误22角度io错误-example@1.0.0开始:
webpack开发服务器--内联--进度--端口8080
22错误退出
在角度io上,状态1 23错误失败-example@1.0.0开始脚本。
23错误这可能不是npm的问题。有可能
上面的附加日志输出。24详细退出[1,true]
它会成功的
npm cache clean --force
npm install
npm start
我发现了一种更简单的方法。完全放弃“npm启动”和webpack方法,使用angular cli。使用angular cli,调用“ng build--prod”处理所有事情(aot等)。在幕后,它使用webpack,但它处理了所有涉及的复杂问题,因此开发人员不必这样做。我只是通过验证和清理缓存,然后将npm更新到最新版本来解决这个问题
npm cache verify
npm install
npm start
如果
npm clean cache--force
npm install
npm start
对您不起作用。尝试重命名根文件夹。它对我来说非常有效。你能分享你的webpack.config.js
文件吗?我现在已经和webpack.common.js、webpack.dev.js和webpack.prod.jsnpm一起分享了它。干净的缓存不起作用。它返回可用的npm使用命令。npm cache clean将返回此“截至”npm@5,npm缓存自修复损坏问题,并保证从缓存提取的数据有效。如果要确保所有内容一致,请改用“npm缓存验证”。我尝试了消息中所述的“npm缓存验证”,然后是“npm启动”,但问题仍然存在。尝试:npm缓存清理--强制否,我没有先删除节点\ U模块。。。。我现在已经删除了node_模块,并重新运行命令“npm clean cache--force”、“npm install”,最后是“npm start”。这个问题仍然存在。这实际上是可行的,我在react native中遇到了类似的问题,这很有效,谢谢