Webpack 如何使用Angular5解决网页包生成错误,我看到…node_modules/xxxx不是编译输出的一部分
我最近升级到了最新的角度状态器,它本身工作得很好。然而,在我的项目中,我看到了一些错误,如:Webpack 如何使用Angular5解决网页包生成错误,我看到…node_modules/xxxx不是编译输出的一部分,webpack,angular5,Webpack,Angular5,我最近升级到了最新的角度状态器,它本身工作得很好。然而,在我的项目中,我看到了一些错误,如: Module build failed: Error: /home/joel/.../Tracker3/node_modules/angular2-color-picker/lib/index.ts is not part of the compilation output. 我曾尝试将此源文件直接包含在我的tsconfig.json或tsconfig.webpack.json中,但这些更改没有效果
Module build failed: Error: /home/joel/.../Tracker3/node_modules/angular2-color-picker/lib/index.ts is not part of the compilation output.
我曾尝试将此源文件直接包含在我的tsconfig.json或tsconfig.webpack.json中,但这些更改没有效果。显然,我还不明白如何正确处理由于添加了带有E angular5的ngc网页而带来的变化
“npm运行生成”给出:(显示生成错误的主机)
不知何故没有被包括在内,但这不可能是正确的,因为当我直接包括它们时,没有任何改进。那么我做错了什么?如何正确设置这几个节点包的构建???为什么其他的软件包都能正常工作??或者我怎样才能学会如何解决这个问题
我在这里包括了我认为相关的配置文件:
第一个:webpack.dev.ts:
/**
* @author: @AngularClass
*/
const helpers = require('./helpers');
const buildUtils = require('./build-utils');
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
const commonConfig = require('./webpack.common.js'); // the settings that are common to prod and dev
const fs = require('fs');
/**
* Webpack Plugins
*/
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
const EvalSourceMapDevToolPlugin = require('webpack/lib/EvalSourceMapDevToolPlugin');
/**
* Webpack configuration
*
* See: http://webpack.github.io/docs/configuration.html#cli
*/
module.exports = function (options) {
const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || 3000;
const METADATA = Object.assign({}, buildUtils.DEFAULT_METADATA, {
host: HOST,
port: PORT,
ENV: ENV,
HMR: helpers.hasProcessFlag('hot'),
PUBLIC: process.env.PUBLIC_DEV || HOST + ':' + PORT
});
return webpackMerge(commonConfig({ env: ENV, metadata: METADATA }), {
/**
* Options affecting the output of the compilation.
*
* See: http://webpack.github.io/docs/configuration.html#output
*/
output: {
/**
* The output directory as absolute path (required).
*
* See: http://webpack.github.io/docs/configuration.html#output-path
*/
path: helpers.root('dist'),
/**
* Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here!
*
* See: http://webpack.github.io/docs/configuration.html#output-filename
*/
filename: '[name].bundle.js',
/**
* The filename of the SourceMaps for the JavaScript files.
* They are inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
*/
sourceMapFilename: '[file].map',
/** The filename of non-entry chunks as relative path
* inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
*/
chunkFilename: '[id].chunk.js',
library: 'ac_[name]',
libraryTarget: 'var',
},
module: {
rules: [
/**
* Css loader support for *.css files (styles directory only)
* Loads external css styles into the DOM, supports HMR
*
*/
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
include: [helpers.root('src', 'styles')]
},
/**
* Sass loader support for *.scss files (styles directory only)
* Loads external sass styles into the DOM, supports HMR
*
*/
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: [helpers.root('src', 'styles')]
},
]
},
plugins: [
new EvalSourceMapDevToolPlugin({
moduleFilenameTemplate: '[resource-path]',
sourceRoot: 'webpack:///'
}),
/**
* Plugin: NamedModulesPlugin (experimental)
* Description: Uses file names as module name.
*
* See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb
*/
new NamedModulesPlugin(),
/**
* Plugin LoaderOptionsPlugin (experimental)
*
* See: https://gist.github.com/sokra/27b24881210b56bbaff7
*/
new LoaderOptionsPlugin({
debug: true,
options: { }
}),
// TODO: HMR
],
/**
* Webpack Development Server configuration
* Description: The webpack-dev-server is a little node.js Express server.
* The server emits information about the compilation state to the client,
* which reacts to those events.
*
* See: https://webpack.github.io/docs/webpack-dev-server.html
*/
devServer: {
port: METADATA.port,
host: METADATA.host,
hot: METADATA.HMR,
public: METADATA.PUBLIC,
historyApiFallback: true,
https: {
key: fs.readFileSync('/etc/apache2/certwork/newDragon.key'),
cert: fs.readFileSync('/etc/apache2/certwork/STAR_dynazu_com.crt'),
ca: fs.readFileSync('/etc/apache2/certwork/ssl-bundle.crt')
},
watchOptions: {
// if you're using Docker you may need this
// aggregateTimeout: 300,
// poll: 1000,
ignored: /node_modules/
},
/**
* Here you can access the Express app object and add your own custom middleware to it.
*
* See: https://webpack.github.io/docs/webpack-dev-server.html
*/
setup: function(app) {
// For example, to define custom handlers for some paths:
// app.get('/some/path', function(req, res) {
// res.json({ custom: 'response' });
// });
}
},
/**
* Include polyfills or mocks for various node stuff
* Description: Node configuration
*
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: true,
crypto: 'empty',
process: true,
module: false,
clearImmediate: false,
setImmediate: false
}
});
}
情节变得更加复杂:为了进一步挖掘,我做了一个“npm运行build:prod”,它以不同的方式失败:
57% building modules 396/442 modules 46 active ...odules/rxjs/operators/windowToggle.jsModuleNotFoundError: Module not found: Error: Can't resolve '../../../../../node_modules/ng2-dnd/style.css' in '/home/joel/workspace/Tracker3/src/app/tracker/west/listHeader'
at factoryCallback (/home/joel/workspace/Tracker3/node_modules/webpack/lib/Compilation.js:276:40)
at factory (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:235:20)
at resolver (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:60:20)
at asyncLib.parallel (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:127:20)
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:3874:9
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:473:16
at iteratorCallback (/home/joel/workspace/Tracker3/node_modules/async/dist/async.js:1048:13)
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:958:16
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:3871:13
at resolvers.normal.resolve (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:119:22)
at onError (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:65:10)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at runAfter (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
at innerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:252:11)
at /home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:40:4
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at runAfter (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
at innerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:252:11)
at innerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:144:11)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:249:35)
at resolver.doResolve.createInnerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:44:6)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at afterInnerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:168:10)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:252:11)
resolve '../../../../../node_modules/ng2-dnd/style.css' in '/home/joel/workspace/Tracker3/src/app/tracker/west/listHeader'
using description file: /home/joel/workspace/Tracker3/package.json (relative path: ./src/app/tracker/west/listHeader)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/joel/workspace/Tracker3/package.json (relative path: ./src/app/tracker/west/listHeader)
using description file: /home/joel/workspace/Tracker3/node_modules/ng2-dnd/package.json (relative path: ./style.css)
no extension
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css.json doesn't exist
as directory
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css doesn't exist
那么这两个问题是否有关联呢?如果您有任何见解,谢谢 事实证明,这些问题与需要为angular 5的webpack版本更改而更新的包有关 此外,我在一个scss文件中有一个@include,由于ng2 dnd包中的更改,路径需要更改 对于ng socket io,我停止使用这个包,抓取一些代码并将其直接插入到我的一个类中 在这一点上,我被归结为angular2颜色选择器软件包中的一个错误,该软件包已经一年多没有维护了。因此,我切换到ngx颜色选择器包和所有现在建立
感谢所有关注这个问题的人,希望这个答案能帮助其他人。我将ng socket io包与socket.service.ts文件一起添加到angular starter项目中,以确保它在项目中使用。当我执行“npm运行构建”这是为开发构建的正常方式时,我看到了相同的错误。我已经在angular starter项目中提交了一个问题,我希望有更多知识的人会做出回应。如果我学得足够多,也许我能回答我自己的问题。也许这是Angular 5的问题,但目前还不清楚。
/**
* @author: @AngularClass
*/
const helpers = require('./helpers');
const buildUtils = require('./build-utils');
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
const commonConfig = require('./webpack.common.js'); // the settings that are common to prod and dev
const fs = require('fs');
/**
* Webpack Plugins
*/
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
const EvalSourceMapDevToolPlugin = require('webpack/lib/EvalSourceMapDevToolPlugin');
/**
* Webpack configuration
*
* See: http://webpack.github.io/docs/configuration.html#cli
*/
module.exports = function (options) {
const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || 3000;
const METADATA = Object.assign({}, buildUtils.DEFAULT_METADATA, {
host: HOST,
port: PORT,
ENV: ENV,
HMR: helpers.hasProcessFlag('hot'),
PUBLIC: process.env.PUBLIC_DEV || HOST + ':' + PORT
});
return webpackMerge(commonConfig({ env: ENV, metadata: METADATA }), {
/**
* Options affecting the output of the compilation.
*
* See: http://webpack.github.io/docs/configuration.html#output
*/
output: {
/**
* The output directory as absolute path (required).
*
* See: http://webpack.github.io/docs/configuration.html#output-path
*/
path: helpers.root('dist'),
/**
* Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here!
*
* See: http://webpack.github.io/docs/configuration.html#output-filename
*/
filename: '[name].bundle.js',
/**
* The filename of the SourceMaps for the JavaScript files.
* They are inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
*/
sourceMapFilename: '[file].map',
/** The filename of non-entry chunks as relative path
* inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
*/
chunkFilename: '[id].chunk.js',
library: 'ac_[name]',
libraryTarget: 'var',
},
module: {
rules: [
/**
* Css loader support for *.css files (styles directory only)
* Loads external css styles into the DOM, supports HMR
*
*/
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
include: [helpers.root('src', 'styles')]
},
/**
* Sass loader support for *.scss files (styles directory only)
* Loads external sass styles into the DOM, supports HMR
*
*/
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: [helpers.root('src', 'styles')]
},
]
},
plugins: [
new EvalSourceMapDevToolPlugin({
moduleFilenameTemplate: '[resource-path]',
sourceRoot: 'webpack:///'
}),
/**
* Plugin: NamedModulesPlugin (experimental)
* Description: Uses file names as module name.
*
* See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb
*/
new NamedModulesPlugin(),
/**
* Plugin LoaderOptionsPlugin (experimental)
*
* See: https://gist.github.com/sokra/27b24881210b56bbaff7
*/
new LoaderOptionsPlugin({
debug: true,
options: { }
}),
// TODO: HMR
],
/**
* Webpack Development Server configuration
* Description: The webpack-dev-server is a little node.js Express server.
* The server emits information about the compilation state to the client,
* which reacts to those events.
*
* See: https://webpack.github.io/docs/webpack-dev-server.html
*/
devServer: {
port: METADATA.port,
host: METADATA.host,
hot: METADATA.HMR,
public: METADATA.PUBLIC,
historyApiFallback: true,
https: {
key: fs.readFileSync('/etc/apache2/certwork/newDragon.key'),
cert: fs.readFileSync('/etc/apache2/certwork/STAR_dynazu_com.crt'),
ca: fs.readFileSync('/etc/apache2/certwork/ssl-bundle.crt')
},
watchOptions: {
// if you're using Docker you may need this
// aggregateTimeout: 300,
// poll: 1000,
ignored: /node_modules/
},
/**
* Here you can access the Express app object and add your own custom middleware to it.
*
* See: https://webpack.github.io/docs/webpack-dev-server.html
*/
setup: function(app) {
// For example, to define custom handlers for some paths:
// app.get('/some/path', function(req, res) {
// res.json({ custom: 'response' });
// });
}
},
/**
* Include polyfills or mocks for various node stuff
* Description: Node configuration
*
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: true,
crypto: 'empty',
process: true,
module: false,
clearImmediate: false,
setImmediate: false
}
});
}
57% building modules 396/442 modules 46 active ...odules/rxjs/operators/windowToggle.jsModuleNotFoundError: Module not found: Error: Can't resolve '../../../../../node_modules/ng2-dnd/style.css' in '/home/joel/workspace/Tracker3/src/app/tracker/west/listHeader'
at factoryCallback (/home/joel/workspace/Tracker3/node_modules/webpack/lib/Compilation.js:276:40)
at factory (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:235:20)
at resolver (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:60:20)
at asyncLib.parallel (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:127:20)
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:3874:9
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:473:16
at iteratorCallback (/home/joel/workspace/Tracker3/node_modules/async/dist/async.js:1048:13)
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:958:16
at /home/joel/workspace/Tracker3/node_modules/async/dist/async.js:3871:13
at resolvers.normal.resolve (/home/joel/workspace/Tracker3/node_modules/webpack/lib/NormalModuleFactory.js:119:22)
at onError (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:65:10)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at runAfter (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
at innerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:252:11)
at /home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:40:4
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at runAfter (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
at innerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:252:11)
at innerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:144:11)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:249:35)
at resolver.doResolve.createInnerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:44:6)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at afterInnerCallback (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/Resolver.js:168:10)
at loggingCallbackWrapper (/home/joel/workspace/Tracker3/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
at next (/home/joel/workspace/Tracker3/node_modules/tapable/lib/Tapable.js:252:11)
resolve '../../../../../node_modules/ng2-dnd/style.css' in '/home/joel/workspace/Tracker3/src/app/tracker/west/listHeader'
using description file: /home/joel/workspace/Tracker3/package.json (relative path: ./src/app/tracker/west/listHeader)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/joel/workspace/Tracker3/package.json (relative path: ./src/app/tracker/west/listHeader)
using description file: /home/joel/workspace/Tracker3/node_modules/ng2-dnd/package.json (relative path: ./style.css)
no extension
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css.json doesn't exist
as directory
/home/joel/workspace/Tracker3/node_modules/ng2-dnd/style.css doesn't exist