在构建时面对`找不到模块'@ babel / plugin-transform-react-jsx'`

时间:2018-11-04 12:41:17

标签: babel bitbucket-pipelines parceljs

使用bitbucket管道构建我的(以前可以正常工作的)应用时,我遇到以下错误:

...

[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
└─ babel-core@6.26.3
Done in 22.08s.
  /opt/atlassian/pipelines/agent/build/src/index.js: Cannot find module '@babel/plugin-transform-react-jsx'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (/opt/atlassian/pipelines/agent/build/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at /opt/atlassian/pipelines/agent/build/node_modules/parcel-bundler/lib/transforms/babel/jsx.js:51:22
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/opt/atlassian/pipelines/agent/build/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (/opt/atlassian/pipelines/agent/build/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
npm info lifecycle parcel-react@1.0.0~build: Failed to exec build script
npm ERR! Linux 4.14.63-coreos
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v7.10.1
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! parcel-react@1.0.0 build: `parcel build index.html --public-url ./`
npm ERR! Exit status 1
...

我的package.json的脚本和与依赖关系有关的行如下所示:

  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build index.html --public-url ./",
    "deploy": "firebase deploy --token $FIREBASE_TOKEN"
  },
  ...
  "dependencies": {
    "axios": "^0.18.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "classnames": "^2.2.6",
    "firebase": "^5.5.7",
    "immutable": "^3.8.2",
    "lodash": "^4.17.10",
    "mark-twain": "^2.0.3",
    "node-sass": "^4.7.2",
    "parcel-plugin-markdown": "^0.3.1",
    "react": "^0.14.0 || ^15.0.0-0 || ^16.0.0-0",
    "react-dom": "^16.2.0",
    "react-iframe": "^1.3.3",
    "react-redux": "^5.0.7",
    "react-router-dom": "^4.3.1",
    "redux": "^2.0.0 || ^3.0.0 || ^4.0.0-0",
    "redux-actions": "^2.6.1",
    "redux-axios-middleware": "^4.0.0",
    "simple-markdown": "^0.4.2",
    "slate": "^0.38.1",
    "slate-plain-serializer": "^0.6.0",
    "slate-react": "^0.16.1"
  },
  "devDependencies": {
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "firebase-tools": "^3.19.3",
    "parcel-bundler": "^1.5.1"
  }

有人知道导致此错误的原因是什么,并且源于哪个依赖项?我试图删除所有babel依赖项,只是为了进行测试,但仍然出现错误。

2 个答案:

答案 0 :(得分:0)

在管道中使用纱线代替npm解决了该问题。我还是在开发中使用了纱线。

答案 1 :(得分:0)

在bitbucket中,点击管道,在右上角可以访问缓存,在那里你可以清除node_modules缓存并重新运行,它应该构建