简体   繁体   English

将 App.Js 导入节点时的 BABEL_PARSE_ERROR

[英]BABEL_PARSE_ERROR when importing App.Js into node

So i have been trying to get my ejected create-react-app, switched to be server side rendered.所以我一直试图让我弹出的 create-react-app 切换到服务器端呈现。 This is a simplified version of my file structure:这是我的文件结构的简化版本:

...
/client
  /build
  /public
  package.json
  /src
    index.js
    /components
      /app
        App.js
/routes
  /api
    Canvas.js
.babelrc
server.js
package.json
...

I am trying to import App.js into Canvas.Js, So that i can use it in a ReactDOMServer.renderToString();我正在尝试将 App.js 导入 Canvas.Js,以便我可以在 ReactDOMServer.renderToString() 中使用它; The problem though, is on the actual import.但是,问题在于实际导入。 The import brings up this error:导入会出现此错误:

client/src/components/app/App.js: Unexpected token (34:4)

  32 | 
  33 |   return (
> 34 |     <div>
     |     ^
  35 |       <IconSettings
    at Parser.raise (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/location.js:41:63)
    at Parser.unexpected (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/util.js:150:16)
    at Parser.parseExprAtom (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:1116:20)
    at Parser.parseExprSubscripts (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:526:23)
    at Parser.parseMaybeUnary (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:506:21)
    at Parser.parseExprOps (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:295:23)
    at Parser.parseMaybeConditional (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:247:23)
    at Parser.parseMaybeAssign (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:195:21)
    at Parser.parseParenAndDistinguishExpression (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:1293:16)
    at Parser.parseExprAtom (/Users/braydenparkinson/dev/workingAppopsCopy/appops-app/node_modules/@babel/parser/src/parser/expression.js:1023:21) {
  pos: 1681,
  loc: Position { line: 34, column: 4 },
  code: 'BABEL_PARSE_ERROR'
}

I am just pulling it in with:我只是把它拉进来:

const App = require('../../client/src/components/app/App');

And i have used both require and import, with the same result.我同时使用了 require 和 import,结果相同。 Not that, that should change anything but in case anyone asks.不是这样,那应该改变任何事情,但万一有人问。

Here is my babelrc:这是我的 babelrc:

{
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "plugins": ["@babel/plugin-transform-react-jsx"]
}

Heres my package.json:这是我的 package.json:

{
  "name": "express-canvas-app",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "babel-node server.js",
    "build": "babel server.js --out-file server.compiled.js",
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.8.4",
    "@babel/node": "^7.8.4",
    "@babel/preset-env": "^7.8.4",
    "@babel/preset-react": "^7.0.0-beta.40",
    "@babel/register": "7.8.3",
    "@material-ui/core": "^4.4.3",
    "@salesforce-ux/design-system": "^2.10.2",
    "@salesforce/design-system-react": "^0.10.16",
    "aws-param-store": "^3.2.0",
    "aws-sdk": "^2.594.0",
    "axios": "^0.19.0",
    "babel-eslint": "^10.0.3",
    "babel-loader": "^8.0.6",
    "babel-preset-es2015": "^6.24.1",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "crypto-js": "^3.1.9-1",
    "dotenv": "^8.2.0",
    "enzyme": "^3.10.0",
    "express": "^4.17.1",
    "express-sse": "^0.5.1",
    "fs": "0.0.1-security",
    "http": "0.0.0",
    "https": "^1.0.0",
    "jsforce": "^1.9.3",
    "node-cache": "^5.1.0",
    "path": "^0.12.7",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.3.1",
    "salesforce-signed-request": "0.0.1",
    "validator": "^11.1.0",
    "webpack-node-externals": "^1.7.2"
  },
  "devDependencies": {
    "@salesforce/babel-preset-design-system-react": "^3.0.0",
    "eslint": "^6.6.0",
    "eslint-config-airbnb": "^18.0.1",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-jest": "^23.0.4",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.16.0",
    "eslint-plugin-react-hooks": "^1.7.0",
    "nodemon": "^1.19.2",
    "npm-run-all": "^4.1.5",
    "salesforce-signed-request": "0.0.1",
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10",
    "webpack-node-externals": "^1.7.2"
  }
}

Any help or ideas would be awesome!任何帮助或想法都会很棒! I have spent the last couple days trying to nail down my errors and get babel configured!过去几天我一直在努力确定我的错误并配置 babel!

I think in this particular case, i still had some webpack and package json files in the client folder.我认为在这种特殊情况下,我仍然在客户端文件夹中有一些 webpack 和 package json 文件。 After porting over logic to a new app with webpack.server.js and package.json only living at root, i seem to have fixed the issue.在使用 webpack.server.js 和 package.json 将逻辑移植到一个新的应用程序后,我似乎已经解决了这个问题。

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

相关问题 错误 in./src/app.js 模块构建失败(来自./node_modules/babel-loader/lib/index.js):错误:找不到模块'@babel/preset-present-env' - ERROR in ./src/app.js Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module '@babel/preset-present-env' 将页面导入 App.js 时,它显示为空白 - When importing page to App.js it shows up blank 将 web3 导入 app.js 时出现许多错误 - Numerous errors when importing web3 into app.js 当我尝试运行我的节点 app.js 时,我的命令行出错 - Error in my command line when i tried to run my node app.js 安装app.js错误Node.js - Installing app.js error Node.js 运行node js编写的app.js文件时,错误来自passport-local-mongoose(一个节点模块) - Error coming from passport-local-mongoose, a node module when running my app.js file written in node js 节点app.js返回错误:连接ECONNREFUSED 127.0.0.1:27017 - Node app.js returns Error: connect ECONNREFUSED 127.0.0.1:27017 Node Express app.js 为 GET 请求提供 404 错误 - Node Express app.js giving a 404 error for GET request 将路由存储在文件中并导入 App.js - Storing routes in a file and importing into App.js Expo SDK 44 升级错误 - App.js: [BABEL]: Unexpected token '.' - Expo SDK 44 upgrade ERROR - App.js: [BABEL]: Unexpected token '.'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM