无法执行启动脚本



角度:5.0.1/Angular CLI:1.5.0/节点:8.9.1/npm:5.5.1/Os:win32 x64

在终端/命令提示符下执行"npm start"时,我收到以下错误。有人能帮我解决这个问题吗?我花了一整天的时间试图把它修好,但没有成功。

这是我的包的脚本部分。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 verbose cli'C:\ProgramFiles\nodejs\node_modules\npm\bin\npm cli.js',1 verbose cli
'start']2信息使用npm@5.5.13信息使用node@v8.9.14详细运行脚本['prestart','start','poststart']5信息生命周期angular-io-example@1.0.0~启动前:angular-io-example@1.0.06条信息生命周期angular-io-example@1.0.0~开始:angular-io-example@1.0.07.详细生命周期angular-io-example@1.0.0~start:烫发不安全生命周期true 8详细生命周期angular-io-example@1.0.0~开始:路径:C:\ProgramFiles\nodejs\node_modules\npm\bin\node gyp-bin;C: \Users\cbonsu\Downloads\sample_pro\webpack\node_modules.bin;C: \WINDOWS\system32;C: \WINDOWS;C: \WINDOWS\System32\Wbem;C: \WINDOWS\System32\WindowsPowerShell\v1.0\;C: \程序Files\Microsoft SQL Server\130\Tools\Binn\;C: \程序Files\Git\cmd;C: \Program Files(x86)\Microsoft SQL服务器\130\Tools\Binn\;C: \Program Files(x86)\Microsoft SQL服务器\130\DTS\Binn\;C: \Program Files\Microsoft SQL服务器\130\DTS\Binn\;C: \Program Files\Microsoft SQL Server\ClientSDK\ODBC\130\Tools\Binn\;C: \Program Files(x86)\Microsoft SQLServer\Client SDK\ODBC\130\Tools\Binn\;C: \程序文件(x86)\Microsoft SQLServer\130\Tools\Binn\ManagementStudio\;C: \WINDOWS\system32\config\systemprofile.dnx\bin;C: \程序Files\Microsoft DNX\Dnvm\;C: \Program Files\Microsoft\Web平台安装程序\;C: \Program Files\dotnet\;C: \程序Files\nodejs\;C: \Users\cbonsu\AppData\Local\Microsoft\WindowsApps;C: \程序Files\nodejs;C: \Program Files\Microsoft VS代码\bin;C: \Users\cbonsu\AppData\Roaming\npm 9详细生命周期angular-io-example@1.0.0~开始: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愚蠢生命周期angular-io-example@1.0.0~开始:返回:代码:1信号:null 12信息生命周期angular-io-example@1.0.0~start:执行失败启动脚本13详细堆栈错误:angular-io-example@1.0.0开始:webpack-dev-server --inline --progress --port 808013详细堆栈在EventEmitter退出状态1 13详细堆栈。(C:\程序Files\nodejs\node_modules\npm\node_modeles\npm lifecycle\index.js:280:16)13在emitTwo的详细堆栈(events.js:126:13)13在EventEmitter.emit的详细堆栈
(events.js:214:7)13在ChildProcess。(C:\程序Files\nodejs\node_modules\npm\node_modeles\npm lifecycle\lib\power.js:55:14)13在emitTwo的详细堆栈(events.js:126:13)13在ChildProcess.emit的详细堆栈
(events.js:214:7)13在maybeClose(internal/child_process.js:925:16)13详细堆栈Process.ChildProcess.handle.onext(internal/child_Process.js:209:5)14详细pkgidangular-io-example@1.0.015详细cwdC: \Users\cbonsu\Downloads\sample_pro\webpack 16详细Windows_NT10.0.15063 17 verbose argv"C:\Program Files\nodejs\node.exe"C:\Program Files\nodejs\node_modules\npm\bin\npm cli.js"start"18 verbose node v8.9.1 19 verbose npm v.5.1 20错误代码ELIFECYCLE 21错误错误no 1 22错误angular-io-example@1.0.0开始:webpack-dev-server --inline --progress --port 808022错误退出状态1 23错误在失败angular-io-example@1.0.0启动脚本。23错误这可能不是npm的问题。很可能上面的附加日志输出。24详细退出[1,true]

它应该使其成为

npm cache clean --force
npm install
npm start 

我只是通过验证和清理缓存,然后将npm更新到最新版本来解决这个问题。

npm cache verify
npm install
npm start

如果npm clean cache --forcenpm installnpm start不适合您。尝试重命名根文件夹。这对我来说是一项零散的工作。

我发现了一种更简单的方法。完全放弃"npm-start"和webpack方法,使用angular cli。使用angular cli,调用"ng-build--prod"可以处理所有事务(aot等)。在幕后,它使用了webpack,但它处理了所有涉及的复杂问题,因此开发人员不必这么做

要修复依赖树,请按照以下步骤执行:

  1. 删除项目文件夹中的package-lock.json(而不是package.json!)和/或yarn.lock
  2. 删除项目文件夹中的node_modules
  3. 删除";webpack开发服务器";来自项目文件夹中package.json文件中的dependencies和/或devDependencies
  4. 根据您使用的包管理器,运行npm install或yarn

最新更新