簡體   English   中英

Babel編譯導致:syntaxError:意外的令牌(38:4)

[英]Babel compilation leads to: syntaxError: Unexpected token (38:4)

我是Node和React的新手,當我嘗試構建Babel以便上傳serverjs並將客戶端反應給Heroku時,我收到此錯誤。

在Postman中一切正常,但無法將其上傳到Heroku。 在網上搜索后,我發現我必須先用Babel編譯它。

錯誤消息是:

SyntaxError: client/node_modules/@babel/helper-plugin-utils/src/index.js: Unexpected token (38:4)
  36 | 
  37 |   return {
> 38 |     ...proto,
     |     ^
  39 |     ...api,
  40 |   };
  41 | }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Baraa\AppData\Roaming\npm-cache\_logs\2019-03-21T16_14_47_767Z-debug.log

我的webpack.config.js文件包含:

module.exports = {
  entry: "./client/src/index.js",
  output: {
    path: __dirname + "/public",
    filename: "bundle.js"
  },
  module: {
    test: /\.jsx?$/,
    exclude: /node_modules/,
    use: [
      {
        loader: "babel-loader",
        options: {
          presets: ["react"]
        }
      }
    ]
  },
  devServer: {
    proxy: {
      "/name": "http://localhost:3011"
    }
  }
};



package.json
{
  "name": "app04",
  "version": "1.0.0",
  "engines": {
    "node": "11.8.0"
  },
  "description": "app 04",
  "main": "server.js",
  "scripts": {
    "build-babel": "babel -d ./build ./ -s",
    "build": "npm run build-babel",
    "start": "npm run build && node ./build/server.js"
  },
  "author": "Baraa Rashad",
  "dependencies": {
    "accuweather": "^1.0.1",
    "axios": "^0.18.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "body-parser": "^1.18.3",
    "bootstrap": "^3.4.1",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "crypto-js": "^3.1.9-1",
    "ejs": "^2.5.2",
    "express": "^4.14.0",
    "http": "0.0.0",
    "nvm": "0.0.4",
    "react": "^15.3.2",
    "react-dom": "^15.3.2",
    "react-json-pretty": "^2.0.0",
    "react-router-config": "^4.4.0-beta.6",
    "react-router-dom": "^4.3.1",
    "reactstrap": "^7.1.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-react": "^6.16.0",
    "babel-preset-stage-2": "^6.17.0",
    "babel-register": "^6.26.0",
    "nodemon": "^1.18.10"
  }
}



.babelrc
{
  "presets": ["env", "es2015", "react"],
  "plugins": ["babel-plugin-transform-class-properties"]
}

我通過調整package.josn找到了解決方案,如下所示。

  "scripts": { "devstart": "babel-node ./src/bin/www", "start": "npm run build && node ./build/bin/www", "build": "npm run babel-build", "babel-build": "babel -d ./build ./src -s", "heroku-postbuild": "cd client && npm install && npm run build" }, 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM