当我尝试使用Webpack和Babel-loader构建我的应用程序时,我收到此错误:
ERROR in ./src/entry.js
Module parse failed: /home/james/projects/fun-time-phonics/node_modules/babel-loader/index.js!/home/james/projects/fun-time-phonics/src/entry.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import React from "react";
| import onReady from "./on-ready";
| import "babel-polyfill";
我的.babelrc
看起来像这样:
{
"presets": ["react", "stage-0"]
}
相关的webpack加载器:
{test: ext("js"), exclude: /node_modules/, loader: "babel"}
模块版本:
"webpack": "^1.12.1",
"babel": "^6.3.26",
"babel-core": "^6.4.0",
"babel-loader": "^6.2.1",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
Babel 5的一切都很好。任何帮助都会非常感激。
更新:
添加babel-preset-es2015后,我的构建现在在静态类属性上失败(尽管babel-preset-stage-0
添加了静态属性):
ERROR in ./src/components/admin/level-score.js
Module build failed: SyntaxError: /home/james/projects/fun-time-phonics/src/components/admin/level-score.js: Missing class properties transform.
4 |
5 | export default class LevelScore extends React.Component {
> 6 | static defaultProps = {
| ^
7 | format: "dash"
8 | };
9 |
at File.buildCodeFrameError (/home/james/projects/fun-time-phonics/node_modules/babel-core/lib/transformation/file/index.js:408:15)
at NodePath.buildCodeFrameError (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/path/index.js:148:26)
at pushBody (/home/james/projects/fun-time-phonics/node_modules/babel-plugin-transform-es2015-classes/lib/vanilla.js:277:20)
at buildBody (/home/james/projects/fun-time-phonics/node_modules/babel-plugin-transform-es2015-classes/lib/vanilla.js:244:10)
at run (/home/james/projects/fun-time-phonics/node_modules/babel-plugin-transform-es2015-classes/lib/vanilla.js:151:10)
at PluginPass.ClassExpression (/home/james/projects/fun-time-phonics/node_modules/babel-plugin-transform-es2015-classes/lib/index.js:63:60)
at newFn (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/visitors.js:276:19)
at NodePath._call (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/path/context.js:74:18)
at NodePath.call (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/path/context.js:46:17)
at NodePath.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/path/context.js:104:12)
at TraversalContext.visitQueue (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:153:16)
at TraversalContext.visitSingle (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:113:19)
at TraversalContext.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:197:19)
at Function.traverse.node (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/index.js:139:17)
at NodePath.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/path/context.js:114:22)
at TraversalContext.visitQueue (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:153:16)
at TraversalContext.visitMultiple (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:108:17)
at TraversalContext.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:195:19)
at Function.traverse.node (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/index.js:139:17)
at NodePath.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/path/context.js:114:22)
at TraversalContext.visitQueue (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:153:16)
at TraversalContext.visitQueue (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:159:21)
at TraversalContext.visitQueue (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:159:21)
at TraversalContext.visitMultiple (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:108:17)
at TraversalContext.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:195:19)
at Function.traverse.node (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/index.js:139:17)
at NodePath.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/path/context.js:114:22)
at TraversalContext.visitQueue (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:153:16)
at TraversalContext.visitSingle (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:113:19)
at TraversalContext.visit (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/context.js:197:19)
at Function.traverse.node (/home/james/projects/fun-time-phonics/node_modules/babel-traverse/lib/index.js:139:17)
@ ./src/components/admin/sections/1.js 23:18-43