【发布时间】:2019-08-20 21:37:03
【问题描述】:
我从 babel 6 迁移到 babel 7。我遇到了一些我无法纠正的错误。
未知:意外的令牌(即使我使用的是@babel/plugin-proposal-object-rest-spread)。
这个问题在我运行 jest 单元测试套件时出现。
错误日志:
► yarn run test:unit
yarn run v1.13.0
$ jest --clearCache && jest --coverage=false
Cleared /tmp/jest_rs
FAIL test/unit/store.test.js
● Test suite failed to run
unknown: Unexpected token (55:10)
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
unknown: Unexpected token (55:10)
53 | mainMenu: [
54 | {
> 55 | ...this.$store.state.routes.home,
| ^
56 | type: Utils.MenuRecordType.PAGE,
57 | name: this.$t(`main_menu.${this.$store.state.routes.home.key}`),
58 | children: []
我的babel.config.js 和我的jest.config.js。 (由于 stackoverflow 的限制,这里没有发布(您的帖子中的代码太多......)。
完整的代码可以在github找到。
【问题讨论】:
-
您是在构建站点时还是在运行 Jest 时遇到这些错误?你正在运行哪个 npm 命令来启动 Jest?
-
看来你根本没有开玩笑的 babel 配置。创建 .babelrc
-
@MattOestreich,您提供的链接错误。链接一用于 babel 6,没有 babel 7。第二个链接似乎与此问题无关。
-
@Aldarund,不,我已经有一个 babel 配置。由于 stackoverflow 代码限制(对于您发布的许多代码……)、check my babel.config.js 和我的jest.config.js,我不能把它放在这里
标签: vue.js jestjs babeljs nuxt.js babel-jest