- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试在 ES6 项目中设置 Jest。没走多远,因为我一运行 jest
,就开始遇到问题。
.babelrc
{
"presets": [
"@babel/env"
]
}
上面的代码在运行 Jest 时抛出一个 Couldn't find preset "@babel/env"relative to directory
错误。我猜这很好,因为它应该是 @babel/preset-env
无论哪种方式? (虽然两者都适用于我的其余设置......)
但是!当我将预设更改为 @babel/preset-env
时,我收到的错误非常令人困惑:
Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel. (While processing preset: "/Users/.../node_modules/@babel/preset-env/lib/index.js")
这很奇怪,因为我的 Babel 和 Jest devDeps 设置为:
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/register": "^7.0.0",
"babel-jest": "^23.6.0"
}
据我所知,该错误消息完全没有意义。我的下一个想法是检查我的全局 Babel CLI 安装,它是 babel-cli@6.26.0
。更接近,但它不是错误消息中所述的 6.26.3
。我还尝试用最新的 @babel/cli
替换全局包,但没有任何区别。
我可能在这里遗漏了什么?
最佳答案
啊,解决了。由于一些非常奇怪的原因,我不得不在我的本地设置中包含 'babel-core@^7.0.0-0'
,这是我在 babel-jest 中找到的。 npmjs 页面(如下截图):
基本上,运行 npm i -D 'babel-core@^7.0.0-0'
解决了我的问题,让我的 devDeps 变成这样:
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.0",
"@babel/register": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
}
包括 @babel/core
和 babel-core
对我来说似乎很疯狂,但是,嘿,它有效!我猜 6.26.3
错误消息仍然是个谜,因为我根本找不到那个版本的任何 Babel 包,无论是本地还是全局...
关于node.js - Jest : Couldn't find preset "@babel/env" relative to directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54049008/
我很难理解两者之间的区别。有人可以解释为什么@babel/preset-env更有益于其targets ? 最佳答案 所有以 @ 为前缀的包都是 Babel 7 系列的一部分。几年前,npm 发布了他
我目前正在尝试了解 babel 配置,但被 babel-preset-** 弄糊涂了,babel 中有很多预设,比如 env,es2015, react 和其他人,我知道 babel-preset-e
我的问题是:babel-preset-stage-0 之间有什么区别? , babel-preset-stage-1 , babel-preset-stage-2和 babel-preset-stag
我已经安装了 babel 7.5,理想情况下它应该以 preset-env 包为目标,但不确定它为什么要寻找“babel-preset-es2015”。 你们能告诉我我做错了什么吗?下面是我的代码 p
我有一个 .js 文件,其中 react 导入了一个返回 span 标签的函数,如下所示: makeSpan = (number, prefix) => { return {prefix} {nu
这个问题在这里已经有了答案: Error: Couldn't find preset "react" when installed using npm install --global babel-
我有默认的 jest.config.js,但是当我想运行单元测试时,我收到一条错误消息: 验证错误:找不到预设@vue/cli-plugin-unit-jest/presets/typescript-
我有一个一直在使用 babel-preset-es2015 的 React 项目,它使用 webpack 构建得很好,但是自从我搬到了 babel-preset-env 模块构建失败。 出现此错误消息
我正在尝试转换编译我的 react/es6 代码并且来自 browserify。由于新的 babel 6 版本以及大多数教程现在已经过时的事实,我正在努力创建一个 webpack 构建。这适用于我的
我有一个使用 Typescript 和 @babel/preset-env 的项目。与 Webpack 捆绑失败并显示此错误和以下配置。 如果我取消注释该行,这会强制 @babel/plugin-pr
所以我有一个使用 create-react-app 引导的项目,当尝试使用 react-scripts build 构建时,我收到以下错误输出: 模块构建失败:错误:不允许插件/预设文件导出对象,只能
我正在尝试基于此代码笔示例构建一个简单的 Cloudinary 图像上传:https://codepen.io/team/Cloudinary/pen/QgpyOK -- 我已经将它转换为与 fetc
我使用 npm install --global babel-cli 安装了 Babel CLI(版本 6)。然后我使用 npm install --global babel-preset-react
我正在为我的 React 项目设置 Webpack,并对 babel 感到困惑, babel-core , babel-loader , babel-preset-2015和babel-preset-
如果您在新的 React 版本 0.57 和 TypeScript 中将测试与 Jest 和 Enzyme 集成,它们将无法工作。以下是重现的步骤: 创建一个新的 React Native 项目: r
安装时 npm install browserify babelify babel-preset-es2015 我正面临以下警告信息 npm WARN deprecated babel-preset-
我放置 -preset 选项的参数顺序是否重要?前任: ffmpeg -i source.mp4 -c:v libx264 -b:v 1.5M -c:a aac -b:a 128k -preset f
我有一个带有选择下拉列表的表单,我的选择标签如下所示: 现在我的 JavaScript 函数只是做 alert('test'); .好吧,当我在下拉列表中更改我的选择时,我收到一条错误消息,提示“预
我正在尝试使用 ffmpeg 将 .mpg 转换为 .flv。在其他服务器上我让它工作但在这里使用 ffmpeg 克隆(avconv)它只是不这样做。 最初我正在使用 libfaac 并预设 fast
尝试使用 AVCapureSessions 并尝试以不同的方式显示输出 CMSampleBufferRef(使用 AVCaptureVideoPreviewLayer,显示 CGImage 并将其转换
我是一名优秀的程序员,十分优秀!