贴上错误信息,方便搜索引擎查找类似错误
Jest encountered an unexpected token
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:
D:\学习\vue3-pro\h5-editor\node_modules\_lodash-es@4.17.21@lodash-es\lodash.js:10
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token 'export'
解决方案
网上查了好久,最终找到唯一一种可以解决我的问题的方法,如果网上普遍的方法没用的朋友可以试试
参考地址:Jest setup “SyntaxError: Unexpected token export”
根据问题回复,可以在jest.config.js 中进行如下配置
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!lodash-es)"
]
|