我的所有测试突然失败了。
该错误相当模糊且低级。我不确定我到底应该做什么以及这意味着什么......
我尝试过: - 在全局范围内安装了jest - 全局卸载 jest 并在本地运行 (jest 24.8.0) - 更改了我的节点版本较低和较高(当前使用 10,尝试过 8,并且之前可以使用 10)
下面是我收到的错误...
● Test suite failed to run
SyntaxError: Unexpected token m in JSON at position 0
at JSON.parse (<anonymous>)
3 | *
4 | * @link http://airbnb.io/enzyme/docs/installation/#working-with-react-16
> 5 | * @copyright 2017 Airbnb, Inc.
| ^
6 | */
7 | // const enzyme = require("enzyme");
8 | // const Adapter = require("enzyme-adapter-react-16");
at Runtime._loadModule (node_modules/jest-runtime/build/index.js:568:59)
at Object.<anonymous> (node_modules/entities/lib/decode_codepoint.js:1:106)
at Object.<anonymous> (node_modules/htmlparser2/lib/Tokenizer.js:3:23)
at Object.<anonymous> (node_modules/htmlparser2/lib/Parser.js:1:106)
at Object.<anonymous> (node_modules/htmlparser2/lib/index.js:1:103)
at Object.<anonymous> (node_modules/cheerio/lib/parse.js:4:18)
at Object.<anonymous> (node_modules/cheerio/lib/cheerio.js:5:13)
at Object.<anonymous> (node_modules/cheerio/index.js:5:28)
at Object.<anonymous> (node_modules/enzyme/build/ReactWrapper.js:15:16)
at Object.<anonymous> (node_modules/enzyme/build/index.js:3:21)
at Object.<anonymous> (src/test-setup.js:5:15)
最佳答案
我遇到了同样的问题,花了 4 个多小时调试这个问题,尝试添加 babel、配置插件等等......我决定向同事寻求帮助,3000 万后他确实意识到唯一的事情需要的是:
更新:
'^.+\\.js': 'babel-jest',
至
'^.+\\.js$': 'babel-jest',
注意末尾的 $...babel-jest 在 json 上运行,就像在 js 上一样...
关于reactjs - 语法错误: Unexpected token m in JSON at position 0: Jest fails running tests all of a sudden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56103772/