无法部署反应应用Netlify:ReactDOM.render抛出一个“意外的标记错误”

问题描述 投票:0回答:1

尝试部署一个应用程序的反应时Netlify是给我一个“意外的标记错误”,这是推动我疯了。

我一直在使用地块作为捆绑,因此到目前为止的应用能够同时在浏览器中测试运行正常,但是它始终在每一个建设的尝试与失败,则会出现不承认文件中的渲染方法或JSX语言。我可能做一些非常愚蠢的。

在此先感谢您的帮助!

这是我的index.js出现抛出错误:

import React from "react";
import { render } from "react-dom";
import App from './components/app';
import "sanitize.css/sanitize.css";

render(<App />, document.getElementById("root"));

错误信息:

10:50:14 PM: Executing user command: npm run build
10:50:15 PM: > [email protected] build /opt/build/repo
10:50:15 PM: > parcel build index.html --public-url ./
10:50:17 PM: 🚨  /opt/build/repo/index.js:6:7: Unexpected token (6:7)
10:50:17 PM:   4 | import "sanitize.css/sanitize.css";
10:50:17 PM:   5 |
10:50:17 PM: > 6 | render(<App />, document.getElementById("root"));
10:50:17 PM:     |       ^
10:50:17 PM:   7 |
10:50:18 PM: npm ERR! code ELIFECYCLE
10:50:18 PM: npm ERR! errno 1
10:50:18 PM: npm ERR! [email protected] build: `parcel build index.html --public-url ./`
10:50:18 PM: npm ERR! Exit status 1

我的package.json文件(删除个人信息)的内容:

{
  "name": "DrumMachine",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest --watch",
    "dev": "parcel index.html",
    "build": "parcel build index.html --public-url ./"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": ",
  "devDependencies": {
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.3.0",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.13.0",
    "eslint-config-react-minimal": "^1.0.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-react": "^7.12.4",
    "parcel-bundler": "^1.11.0",
    "react-testing-library": "^5.4.4"
  },
  "jest": {
    "moduleNameMapper": {
      "\\.(css|less|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",
      "\\.(gif|ttf|eot|svg)$": "<rootDir>/__mocks__/fileMock.js"
    }
  },
  "dependencies": {
    "sanitize.css": "^8.0.0",
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.3.0",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "parcel-bundler": "^1.11.0"
  }
}
reactjs netlify parceljs
1个回答
0
投票

缺少项目reactreact-dom依赖。

  "dependencies": {
    "sanitize.css": "^8.0.0",
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.3.0",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "react": "16.8.1",
    "react-dom": "16.8.1",
    "parcel-bundler": "^1.11.0"
  }

用途:npm install react react-dom

注:有devDependenciesdependencies其他模块重复

© www.soinside.com 2019 - 2024. All rights reserved.