Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 汇总[!]错误:antd库的意外标记_Javascript_Reactjs_Rollup - Fatal编程技术网

Javascript 汇总[!]错误:antd库的意外标记

Javascript 汇总[!]错误:antd库的意外标记,javascript,reactjs,rollup,Javascript,Reactjs,Rollup,我正在为antd和redux表单包装器创建npm包。我使用RollUp进行jsx编译。我为依赖项安装了antd lib。当我运行脚本时,它将显示以下错误 > rollup -c src/index.tsx → dist/index.js, dist/index.es.js... [!] Error: Unexpected token node_modules/antd/package.json (2:9) 1: { 2: "_from": "antd@3.19.1",

我正在为antd和redux表单包装器创建npm包。我使用RollUp进行jsx编译。我为依赖项安装了antd lib。当我运行脚本时,它将显示以下错误

> rollup -c

src/index.tsx → dist/index.js, dist/index.es.js...
[!] Error: Unexpected token
node_modules/antd/package.json (2:9)
1: {
2:   "_from": "antd@3.19.1",
            ^
3:   "_id": "antd@3.19.1",
4:   "_inBundle": false,
my rollup.config.js

import typescript from 'rollup-plugin-typescript2'
import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
// import postcss from 'rollup-plugin-postcss-modules'
import postcss from 'rollup-plugin-postcss'
import resolve from 'rollup-plugin-node-resolve'
import url from 'rollup-plugin-url'
import svgr from '@svgr/rollup'
import globals from "rollup-plugin-node-globals";
import builtins from "rollup-plugin-node-builtins";
import json from "rollup-plugin-json";
import pkg from './package.json'

export default {
  input: 'src/index.tsx',
  output: [
    {
      file: pkg.main,
      format: 'cjs',
      exports: 'named',
      sourcemap: true
    },
    {
      file: pkg.module,
      format: 'es',
      exports: 'named',
      sourcemap: true
    }
  ],
  plugins: [
    external(),
    postcss({
      modules: true
    }),
    url(),
    svgr(),
    resolve({preferBuiltins: false}),
    typescript({
      rollupCommonJSResolveHack: true,
      clean: true
    }),
    commonjs(),
    globals(),
    builtins(),
    json()
  ]
}


mypackage.json

{
  "name": "a8formelements",
  "version": "1.0.1",
  "description": "sample",
  "author": "",
  "license": "MIT",
  "repository": "/formelements",
  "main": "dist/index.js",
  "module": "dist/index.es.js",
  "jsnext:main": "dist/index.es.js",
  "engines": {
    "node": ">=8",
    "npm": ">=5"
  },
  "scripts": {
    "test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
    "test:watch": "react-scripts-ts test --env=jsdom",
    "build": "rollup -c",
    "start": "rollup -c -w",
    "prepare": "npm run build",
    "predeploy": "cd example && npm install && npm ru  n build",
    "deploy": "gh-pages -d example/build"
  },
  "dependencies": {
    "antd": "3.19.1",
    "classnames": "^2.2.6",
    "moment": "^2.24.0",
    "uuid": "^3.3.2",
    "validate.js": "^0.12.0"
  },
  "peerDependencies": {
    "prop-types": "^15.5.4",
    "react": "^15.0.0 || ^16.0.0",
    "react-dom": "^15.0.0 || ^16.0.0"
  },
  "devDependencies": {
    "@types/classnames": "^2.2.7",
    "@types/uuid": "^3.4.4",
    "@svgr/rollup": "^2.4.1",
    "@types/jest": "^23.1.5",
    "@types/node": "^11.13.5",
    "@types/react": "^16.8.13",
    "@types/react-dom": "^16.0.5",
    "@types/redux-form": "^8.1.1",
    "babel-core": "^6.26.3",
    "babel-runtime": "^6.26.0",
    "cross-env": "^5.1.4",
    "gh-pages": "^1.2.0",
    "react": "^16.4.1",
    "rollup-plugin-json": "^4.0.0",
    "react-dom": "^16.4.1",
    "react-scripts-ts": "^2.16.0",
    "rollup": "^0.62.0",
    "rollup-plugin-babel": "^3.0.7",
    "rollup-plugin-commonjs": "^9.1.3",
    "rollup-plugin-node-builtins": "^2.1.2",
    "rollup-plugin-node-globals": "^1.4.0",
    "rollup-plugin-node-resolve": "^3.4.0",
    "rollup-plugin-peer-deps-external": "^2.2.0",
    "rollup-plugin-postcss": "^1.6.2",
    "rollup-plugin-typescript2": "^0.20.1",
    "rollup-plugin-url": "^1.4.0",
    "typescript": "^2.8.3"
  },
  "files": [
    "dist"
  ]
}

我用rollup插件json集成更新了我的rollup.config.js。添加此配置时,我遇到了另一个错误,如下所示:

node_modules/rc-editor-mention/es/index.js (2:9)
1: // export this package's api
2: import { ContentState } from 'draft-js';
            ^
3: import Mention from './component/Mention.react';
4: import toString from './utils/exportContent';

你可以找到一个相互询问的讨论。 建议您使用

有点奇怪,但axios节点适配器需要自己的package.json 默认情况下,哪个汇总不理解

要使rollup理解json文件,只需使用rollup插件json即可。 我刚试过,效果很好

有人和你有同样的问题,但axios和我认为是同一个概念


您可以试试。

是否可以发布您的包.json?我已经尝试了rollup插件json。这没用。。。你还有其他建议吗?你能更新你的帖子并展示你是如何集成rollup插件json的吗?我更新了。。。使用rollup插件json。。。它将抛出另一个错误,如2:从'DraftJS'导入{ContentState};[!]错误:node_modules/draft js/lib/draft.js node_modules/rc editor note/es/index.js(2:9)未导出“ContentState”。以上注释是我在配置json()后启动汇总时出现的错误