汇总[!]错误:antd lib的意外令牌

时间:2019-05-31 06:40:20

标签: 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",
            ^
3:   "_id": "antd@3.19.1",
4:   "_inBundle": false,

我的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()
  ]
}


我的package.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-plugin-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';

1 个答案:

答案 0 :(得分:0)

您可以找到有趣的讨论here。 建议您使用rollup-plugin-json

  

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

     

要使汇总了解json文件,只需使用rollup-plugin-json。   我刚刚尝试过,效果很好。

有人遇到了与您相同的问题,但使用axios,我认为这是相同的概念。

您可以尝试一下。