【发布时间】:2017-12-02 22:24:11
【问题描述】:
我在构建模块时遇到以下错误:
模块解析失败: D:\Projects\slacs-new\slacs-portal\portal-aggregator\js-module/src\index.js Unexpected token (1:7) [INFO] 你可能需要一个合适的加载器来 处理这种文件类型。 [INFO] SyntaxError:意外的令牌 (1:7) [信息] 在 Parser.pp$4.raise (D:\Projects\slacs-new\slacs-portal\portal-aggregator\js-module\node_modules\acorn\dist\acorn.js:2221:15) [INFO] 在 Parser.pp.unexpected (D:\Projects\slacs-new\slacs-portal\portal-aggregator\js-module\node_modules\acorn\dist\acorn.js:603:10)
Webpack 配置内容:
var webpack = require('webpack');
var config = {
context: __dirname + '/src', // `__dirname` is root of project and `src` is source
entry: {
app: './index.js',
},
output: {
path: __dirname + '/dist', // `dist` is the destination
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.js$/, // Check for all js files
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: { presets: ['es2015'] }
}]
}
]
}
};
module.exports = config;
我的 package.json
{
"name": "js-module",
"version": "1.0.0",
"dependencies": {
"jquery": "^3.1.1",
"webpack": "^1.13.2"
},
"devDependencies": {
"jquery": "^3.1.1",
"babel-cli": "^6.18.0",
"babel-core": "6.14.0",
"babel-eslint": "^6.1.2",
"babel-loader": "6.2.5",
"babel-plugin-transform-class-properties": "^6.11.5",
"babel-preset-decorators-legacy": "^1.0.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-latest": "^6.14.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.5.0",
"eslint": "^3.9.1",
"eslint-plugin-react": "^6.6.0",
"liferay-module-config-generator": "^1.1.10",
"lr-js-core": "0.0.1",
"webpack": "^1.13.2"
},
"scripts": {
"bundle": "webpack --config webpack.config.js"
}
}
我的 index.js
export $ from 'jquery';
如您所见,我添加了一行,但我无法弄清楚还需要什么!
请对这个话题有所了解
【问题讨论】:
标签: npm webpack ecmascript-6 es6-module-loader