简体   繁体   English

从 Babel 5.8.35 升级到 6.0.0 不会编译带有 SyntaxError 和意外令牌的 app.js

[英]Upgrading from Babel 5.8.35 to 6.0.0 will not compile app.js with a SyntaxError and unexpected token

I am in the process of upgrading all my ReactJS components with webpack .我正在用webpack升级我所有的ReactJS组件。

In the process I have not been able to upgrade from babel 5 to 6. When I do so I get the following stack trace within my app.js class.在这个过程中,我无法从babel 5 升级到 6。当我这样做时,我在app.js类中得到以下堆栈跟踪。

This code worked fine with :此代码适用于:

"babel-core": "^5.8.35",
"babel-loader": "^5.3.3",

But broke once upgrading to 6.0.0但是一旦升级到 6.0.0 就坏了

The code is:代码是:

var objectListMap = this.state.objects.map(object =>
      <EntityObject key={object.entity._links.self.href}
            object={object}
            jsonAttributes={jsonAttributes}
            attributes={this.state.attributes}
            onUpdate={this.onUpdate}
            onDelete={this.onDelete}/>
    );

The Stack trace is:堆栈跟踪是:

 ERROR in ./app.js
 Module build failed: SyntaxError: C:/Work 2016/GitHub/aaronmagi/miwdesign/mcb-server/src/main/resources/static/app.js: Unexpected token (292:3)
   290 |
   291 |          var objectListMap = this.state.objects.map(object =>
 > 292 |                  <EntityObject key={object.entity._links.self.href}
       |                  ^
   293 |                                          object={object}
   294 |                                          jsonAttributes={jsonAttributes}
   295 |                                          attributes={this.state.attributes}
     at Parser.pp.raise (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:1378:13)
     at Parser.pp.unexpected (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:2817:8)
     at Parser.pp.parseExprAtom (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:749:12)
     at Parser.pp.parseExprSubscripts (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:504:19)
     at Parser.pp.parseMaybeUnary (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:484:19)
     at Parser.pp.parseExprOps (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:415:19)
     at Parser.pp.parseMaybeConditional (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:397:19)
     at Parser.pp.parseMaybeAssign (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:360:19)
     at Parser.pp.parseFunctionBody (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:1116:22)
     at Parser.pp.parseArrowExpression (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:1104:8)
     at Parser.pp.parseExprAtom (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:664:21)
     at Parser.pp.parseExprSubscripts (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:504:19)
     at Parser.pp.parseMaybeUnary (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:484:19)
     at Parser.pp.parseExprOps (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:415:19)
     at Parser.pp.parseMaybeConditional (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:397:19)
     at Parser.pp.parseMaybeAssign (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:360:19)
     at Parser.pp.parseExprListItem (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:1206:16)
     at Parser.pp.parseCallExpressionArguments (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:580:20)
     at Parser.pp.parseSubscripts (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:543:29)
     at Parser.pp.parseExprSubscripts (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:514:15)
     at Parser.pp.parseMaybeUnary (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:484:19)
     at Parser.pp.parseExprOps (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:415:19)
     at Parser.pp.parseMaybeConditional (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:397:19)
     at Parser.pp.parseMaybeAssign (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:360:19)
     at Parser.pp.parseVar (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:2274:24)
     at Parser.pp.parseVarStatement (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:2121:8)
     at Parser.pp.parseStatement (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:1831:19)
     at Parser.pp.parseBlockBody (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:2208:21)
     at Parser.pp.parseBlock (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:2189:8)
     at Parser.pp.parseFunctionBody (C:\Work 2016\GitHub\aaronmagi\miwdesign\mcb-server\src\main\resources\static\node_modules\babylon\index.js:1125:22)

package.json包.json

"dependencies": {
    "babel-core": "^6.0.0",
    "babel-loader": "^6.0.0",
    "react": "^15.0.1",
    "react-dom": "^15.0.1",
    "rest": "^1.3.2",
    "sockjs-client": "^1.0.3",
    "stompjs": "^2.3.3",
    "webpack": "^1.13.0"
  },
  "scripts": {
    "watch": "webpack --watch -d"
  }

webpack.config.js webpack.config.js

  var path = require('path');

  var node_dir = __dirname + '/node_modules';

  module.exports = {
      entry: './app.js',
      devtool: 'sourcemaps',
      cache: true,
      debug: true,
      resolve: {
          alias: {
              'stompjs': node_dir + '/stompjs/lib/stomp.js',
              'when': node_dir + '/rest/node_modules/when/when.js'
          }
      },
      output: {
          path: __dirname,
          filename: './built/bundle.js'
      },
      module: {
          loaders: [
              {
                  test: path.join(__dirname, '.'),
                  exclude: /(node_modules)/,
                  loader: 'babel-loader'
                  // TODO remove for production
                  //loaders: ['react-hot','babel-loader']
              }
          ]
      }
  };

UPDATE: The solution was to add the .BABELRC file and update package.json更新:解决方案是添加 .BABELRC 文件并更新 package.json

After adding .babelrc添加 .babelrc 后

{
  "presets": ["es2015", "react"]
}

I then needed to update package.json然后我需要更新 package.json

"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",

You have to install the babel presets你必须安装 babel 预设

react preset反应预设

es2015 preset es2015预设

add a .babelr file to your project where you'll set up your presets将 .babelr 文件添加到您将设置预设的项目中

{
  "presets": ["es2015", "react"]
}

This is a good tutorial if you want to take a look.如果您想看一看, 是一个很好的教程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 app.js:1 �� SyntaxError: Invalid or unexpected token - app.js:1 �� SyntaxError: Invalid or unexpected token Expo SDK 44 升级错误 - App.js: [BABEL]: Unexpected token '.' - Expo SDK 44 upgrade ERROR - App.js: [BABEL]: Unexpected token '.' app.js:40 Uncaught (in promise) SyntaxError: Unexpected end of input - app.js:40 Uncaught (in promise) SyntaxError: Unexpected end of input babel watch SyntaxError:意外的令牌 - babel watch SyntaxError: Unexpected token Post 500 (Internal Server Error) line 48 app.js 和错误 SyntaxError: Unexpected token &lt; in JSON at position 0 line 65 in app.js - Post 500 (Internal Server Error) line 48 app.js and error SyntaxError: Unexpected token < in JSON at position 0 line 65 in app.js ReactJS:语法错误:src / App.js:意外令牌(16:6) - ReactJS :Syntax error: src/App.js: Unexpected token (16:6) Babel编译导致:syntaxError:意外的令牌(38:4) - Babel compilation leads to: syntaxError: Unexpected token (38:4) babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/defineProperty.js:1 SyntaxError: createScript 意外的令牌导出 (vm.js:80:10 - babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/defineProperty.js:1 SyntaxError: Unexpected token export at createScript (vm.js:80:10 React + Redux + Babel(SyntaxError…表示意外的令牌) - React + Redux + Babel (SyntaxError in …state unexpected token) SyntaxError:在Koa中使用异步和Babel的意外令牌 - SyntaxError: Unexpected token using async and babel in koa
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM