Webpack加载器不起作用,所以这里有所有问题信息
OS: windows 10
node: 8.2.1
npm: 5.3.0
我尝试运行npm run dev
时出现控制台错误消息:
ts-loader: Using typescript@2.1.6 and C:\MAMP\htdocs\wordpress\wp-content\themes\angular-project\tsconfig.json
#
# Fatal error in api.cc, line 1200
# Check failed: !value_obj->IsJSReceiver() || value_obj->IsTemplateInfo().
#
==== C stack trace ===============================
v8::internal::interpreter::BytecodeArrayRandomIterator::UpdateOffsetFromIndex [0x00007FF7113BF426+8086]
v8::Template::Set [0x00007FF710EF9FAD+349]
Nan::SetPrototypeTemplate [0x00007FFED066DBA3+131] (c:\mamp\htdocs\wordpress\wp-content\themes\angular-project\node_modules\nan\nan.h:1847)
SassTypes::Boolean::get_constructor [0x00007FFED0672E99+329] (c:\mamp\htdocs\wordpress\wp-content\themes\angular-project\node_modules\node-sass\src\sass_types\boolean.cpp:26)
SassTypes::Factory::initExports [0x00007FFED0675B19+489] (c:\mamp\htdocs\wordpress\wp-content\themes\angular-project\node_modules\node-sass\src\sass_types\factory.cpp:55)
node_module_register [0x00007FF710C47745+2437]
v8::internal::interpreter::Interpreter::GetDispatchCountersObject [0x00007FF7114A1C20+54448]
std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::zone_allocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Reallocate [0x00007FF710FE1598+113688]
std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::zone_allocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Reallocate [0x00007FF710FE0453+109267]
std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::zone_allocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Reallocate [0x00007FF710FE033B+108987]
(No symbol) [0x000002040D6840C1]
npm ERR! code ELIFECYCLE
npm ERR! errno 3221225477
npm ERR! halo-effect@0.0.1 dev: `npm run clean && webpack --config=webpack-dev.config.js`
npm ERR! Exit status 3221225477
npm ERR!
npm ERR! Failed at the halo-effect@0.0.1 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\wagner\AppData\Roaming\npm-cache\_logs\2017-07-24T14_40_15_990Z-debug.log
/c/Program Files/nodejs/npm: line 34: 3084 Segmentation fault "$NODE_EXE" "$NPM_CLI_JS" "$@"
npm list webpack
返回空,但它在node_modules中作为版本1.13.1,如package.json文件中所列:
$ npm list webpack
project-name@0.0.1 C:\MAMP\htdocs\wordpress\wp-content\themes\angular-project
`-- (empty)
的package.json:
{
"name": "my-project",
"keywords": [
"angular",
"typescript"
],
"scripts": {
"generator": "node generator.js",
"clean": "rm -f ../halo-wordpress-theme/css/* && rm -f ../halo-wordpress-theme/js/*",
"dev": "npm run clean && webpack --config=webpack-dev.config.js",
"release": "npm run clean && webpack --config=webpack-release.config.js"
},
"dependencies": {
"@types/angular": "1.6.27",
"@types/angular-cookies": "1.4.4",
"@types/angular-mocks": "1.5.10",
"@types/angular-ui-router": "1.1.37",
"@types/es6-shim": "0.31.34",
"@types/jasmine": "2.5.53",
"@types/jasmine-matchers": "0.2.30",
"@types/lodash": "4.14.71",
"@types/ng-dialog": "0.6.2",
"@types/ng-file-upload": "12.2.1",
"angular": "1.6.5",
"angular-cookies": "1.6.5",
"angular-mocks": "1.6.5",
"@uirouter/angularjs": "1.0.3",
"autoprefixer": "7.1.2",
"bootstrap-sass": "3.3.7",
"clipboard": "1.7.1",
"copy-webpack-plugin": "4.0.1",
"css-loader": "0.28.4",
"extract-text-webpack-plugin": "3.0.0",
"html-loader": "0.4.5",
"lodash": "4.17.4",
"ng-dialog": "1.3.0",
"ng-file-upload": "12.2.13",
"ng-infinite-scroll": "1.3.0",
"ngclipboard": "1.1.1",
"node-sass": "4.5.3",
"postcss-loader": "2.0.6",
"precss": "2.0.0",
"sass-lint": "1.10.2",
"sass-loader": "6.0.6",
"sasslint-webpack-plugin": "1.0.4",
"string": "3.3.3",
"style-loader": "0.18.2",
"ts-loader": "2.3.1",
"tslint": "5.5.0",
"tslint-loader": "3.5.3",
"typescript": "2.4",
"vorpal": "1.12.0",
"webpack": "1.13.1"
}
}
的WebPack-DEV-config.js:
var path = require('path');
var webpack = require('webpack');
var loaders = require("./webpack-loaders");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var autoprefixer = require('autoprefixer');
var precss = require('precss');
var sassLintPlugin = require('sasslint-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var PATHS = {
app: path.join(__dirname, 'src/index.ts'),
dist: path.join(__dirname, '../myproject-wordpress-theme/js/')
};
module.exports = {
devtool: "source-map",
watch: true,
debug: true,
entry: {
app: [
PATHS.app
]
},
output: {
path: PATHS.dist,
filename: '[name].js',
devtoolModuleFilenameTemplate: function(info) {
return "file:///"+info.absoluteResourcePath;
}
},
resolve: {
root: __dirname,
extensions: ['', '.ts', '.js', '.json', '.scss']
},
module: {
loaders: loaders
},
postcss: function () {
return [autoprefixer, precss];
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(true),
new CopyWebpackPlugin([
{from: 'fonts/', to: '../fonts/'}
]),
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin('../css/app.css', { allChunks: true }),
new sassLintPlugin({
configFile: '.sass-lint.yml',
ignoreFiles: [
path.join(__dirname, 'src/common/footer.scss'),
path.join(__dirname, 'src/common/normalize.scss')
],
glob: 'src/**/*.s+(a|c)ss',
ignorePlugins: ['extract-text-webpack-plugin']
})
]
};
的WebPack-loaders.js
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = [
{
test: /\.ts$/,
loader: 'ts-loader'
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader?-url!postcss-loader"),
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader?-url!postcss-loader!sass-loader?outputStyle=expanded")
}
];