作者:手机用户2602897795 | 来源:互联网 | 2022-12-06 15:52
我有这个问题
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:
C:\Code\SPFx\BCO\node_modules\@microsoft\sp-core-library\lib\index.js:11
export { default as _BrowserDetection } from './BrowserDetection';
^^^^^^
SyntaxError: Unexpected token export
19 | } from 'office-ui-fabric-react/lib/Utilities';
20 | import { IUserProvider } from "../UserProviders/IUserProvider";
> 21 | import {
| ^
22 | Environment,
23 | EnvironmentType
24 | } from '@microsoft/sp-core-library';
at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object. (src/webparts/BCO/components/EmployeeSelector/EmployeeSelector.tsx:21:1)
at Object. (src/webparts/BCO/components/FieldMapping/FieldMapping.tsx:13:1)
并在config.json中尝试了这些transformIgnorePatterns表达式
"transformIgnorePatterns": [
"\\node_modules\\@microsoft\\sp-dialog",
"\\node_modules\\@microsoft\\sp-core-library",
"node_modules/(?!sp-core-library)",
"node_modules/(?!@microsoft/sp-core-library)"
],
而且他们都没有工作.我在Windows 10上运行它,所以我也尝试了这种格式