node.js - 无法从 PATH 中找到模块 'babel-preset-env' 您是说 "@babel/env"吗?

标签 node.js jestjs babeljs

Jest cli 突然停止工作,所有测试都失败了:

Cannot find module 'babel-preset-env' from '/PATH'
    - Did you mean "@babel/env"?
我确定使用 babel 6 的模块与使用 babel 7 的项目之间存在某种不兼容,但我不确定如何解决。
这是 package.json
{
  "name": "testing101",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "parcel index.html",
    "test": "jest src/*.js --watchAll",
    "nyc": "nyc ava",
    "build": "babel src/*.js -d dist"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@types/jest": "^24.0.13",
    "jest": "^24.8.0",
    "nyc": "^14.1.1",
    "parcel-bundler": "^1.7.0"
  },
  "jest": {
    "verbose": true,
    "testURL": "http://localhost:1234/",
    "collectCoverage": true
  },
  "dependencies": {
    "axios": "^0.18.0",
    "nock": "^10.0.6"
  }
}
这是 .babelrc
{
  "presets": ["@babel/preset-env"],
  "env": {
    "test": {
      "presets": ["env"]
    }
  }
}

最佳答案

你可以通过 npm 试试

npm install --save-dev @babel/preset-env

关于node.js - 无法从 PATH 中找到模块 'babel-preset-env' 您是说 "@babel/env"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56519158/

相关文章:

javascript - "Name = undefined"模块解析失败

javascript - node.js 模块和函数中 "this"的含义

node.js - ACL 最佳实践,在用户对象中存储角色,还是单独的表/集合?

javascript - 错误: Babel polyfill is required although its already installed

JavaScript Jest 测试;使用回调函数修改数组中的元素

unit-testing - 直接在 Intellij Idea/WebStorm 中运行 Jest 测试?

async-await - 将 next.js 配置为使用 Babel 不转换异步函数

node.js - 服务器可以检查请求是否来自 iframe (Node.js)?

node.js - Mongoose 填充架构中虚拟值的引用

javascript - 如何使用 jest 的参数测试请求 http - Angular