React native React Native/Expo又一个语法错误:测试时意外导入令牌
我正在使用React Native和Expo开发一个移动应用程序 一切都很好,应用程序正在按预期运行 但在导入某些@expo库时,我的测试没有运行 错误是经典的: 语法错误:意外的令牌导入 给出erro的完整上下文:React native React Native/Expo又一个语法错误:测试时意外导入令牌,react-native,ecmascript-6,babeljs,expo,React Native,Ecmascript 6,Babeljs,Expo,我正在使用React Native和Expo开发一个移动应用程序 一切都很好,应用程序正在按预期运行 但在导入某些@expo库时,我的测试没有运行 错误是经典的: 语法错误:意外的令牌导入 给出erro的完整上下文: ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import glyphMap
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import glyphMap
^^^^^^
SyntaxError: Unexpected token import
我还尝试将模块名称更改为:
{
"presets": ["babel-preset-expo", "react-native"],
"env": {
"test": {
"plugins": [
"babel-plugin-dynamic-import-node"
]
}
}
}
不幸的是,这些解决方案都不适合我
为了提供更多的上下文,它是一个在OSX上运行的带有Expo的React本机应用程序
除上述错误外,我还收到另外5条警告。
警告涉及重复的模块名称(可能无关,但无论如何):
jest-haste映射:找到重复的手动模拟:
模块名称:ErrorUtils
重复的模拟路径:://node\u modules/react native/Libraries/Core/\uuuu mocks\uuuu/ErrorUtils.js
此警告是由两个具有相同文件名的手动模拟文件引起的。
Jest将使用在以下位置找到的模拟文件:
//node_modules/react native/Libraries/Core/________/ErrorUtils.js
请删除以下两个文件之一:
//node_modules/react native/node_modules/fbjs/lib/_mocks__/ErrorUtils.js
/project_dir/node_modules/react native/Libraries/Core/__mocks__/ErrorUtils.js
jest haste映射:@providesModule命名冲突:
重复模块名称:camelcase
路径://node_modules/react native/node_modules/yargs parser/node_modules/camelcase/package.json与//node_modules/react native/node_modules/yargs/node_modules/camelcase/package.json冲突
此警告是由跨两个不同文件使用相同名称的@ProvideModule声明引起的。
jest haste映射:@providesModule命名冲突:
重复模块名称:bser
路径://node_modules/react native/node_modules/bser/package.json与//node_modules/react native/node_modules/fb watchman/node_modules/bser/package.json冲突
此警告是由跨两个不同文件使用相同名称的@ProvideModule声明引起的。
jest haste映射:@providesModule命名冲突:
重复模块名称:core js
路径://node_modules/react native/node_modules/core js/package.json与//node_modules/react native/node_modules/fbjs/node_modules/core js/package.json冲突
此警告是由跨两个不同文件使用相同名称的@ProvideModule声明引起的。
jest haste映射:@providesModule命名冲突:
重复模块名称:yargs
路径://node_modules/react native/node_modules/yargs/package.json与//node_modules/react native/node_modules/uglify js/node_modules/yargs/package.json冲突
此警告是由跨两个不同文件使用相同名称的@ProvideModule声明引起的。
版本:
反应本机:0.46.1
@世博会/矢量图标:5.1.0
笑话:20.0.4
还有别的想法吗
****更新****
将transformIgnorePatterns更改为:“/!node\u modules\/\@expo”
这不起作用,但至少会改变为另一个错误
Invariant Violation: Native module cannot be null.
at invariant (node_modules/react-native/node_modules/fbjs/lib/invariant.js:44:7)
at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:31:1)
at Object.<anonymous> (node_modules/expo/src/Location.js:6:26)
at Object.<anonymous> (node_modules/expo/src/Expo.js:8:1)
不变冲突:本机模块不能为null。
at invariant(node_modules/react native/node_modules/fbjs/lib/invariant.js:44:7)
在新的NativeEventMitter(node_modules/react native/Libraries/EventEmitter/nativeEventMitter.js:31:1)
反对。(node_modules/expo/src/Location.js:6:26)
反对。(node_modules/expo/src/expo.js:8:1)
我也有同样的问题。我最终通过删除并重新安装jest expo解决了这个问题。确保您的jest expo版本与您的expo版本相匹配
npm卸载笑话博览会
npm缓存清理#或npm缓存验证(如果节点5+)
npm安装--保存开发笑话博览会
你明白了吗
jest-haste-map: duplicate manual mock found:
Module name: ErrorUtils
Duplicate Mock path: /<project_dir>/node_modules/react-native/Libraries/Core/__mocks__/ErrorUtils.js
This warning is caused by two manual mock files with the same file name.
Jest will use the mock file found in:
/<project_dir>/node_modules/react-native/Libraries/Core/__mocks__/ErrorUtils.js
Please delete one of the following two files:
/<project_dir>/node_modules/react-native/node_modules/fbjs/lib/__mocks__/ErrorUtils.js
/project_dir/node_modules/react-native/Libraries/Core/__mocks__/ErrorUtils.js
jest-haste-map: @providesModule naming collision:
Duplicate module name: camelcase
Paths: /<project_dir>/node_modules/react-native/node_modules/yargs-parser/node_modules/camelcase/package.json collides with /<project_dir>/node_modules/react-native/node_modules/yargs/node_modules/camelcase/package.json
This warning is caused by a @providesModule declaration with the same name across two different files.
jest-haste-map: @providesModule naming collision:
Duplicate module name: bser
Paths: /<project_dir>/node_modules/react-native/node_modules/bser/package.json collides with /<project_dir>/node_modules/react-native/node_modules/fb-watchman/node_modules/bser/package.json
This warning is caused by a @providesModule declaration with the same name across two different files.
jest-haste-map: @providesModule naming collision:
Duplicate module name: core-js
Paths: /<project_dir>/node_modules/react-native/node_modules/core-js/package.json collides with /<project_dir>/node_modules/react-native/node_modules/fbjs/node_modules/core-js/package.json
This warning is caused by a @providesModule declaration with the same name across two different files.
jest-haste-map: @providesModule naming collision:
Duplicate module name: yargs
Paths: /<project_dir>/node_modules/react-native/node_modules/yargs/package.json collides with /<project_dir>/node_modules/react-native/node_modules/uglify-js/node_modules/yargs/package.json
This warning is caused by a @providesModule declaration with the same name across two different files.
Invariant Violation: Native module cannot be null.
at invariant (node_modules/react-native/node_modules/fbjs/lib/invariant.js:44:7)
at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:31:1)
at Object.<anonymous> (node_modules/expo/src/Location.js:6:26)
at Object.<anonymous> (node_modules/expo/src/Expo.js:8:1)