Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 正在将jest传输到src目录之外_Node.js_Reactjs_Jestjs_Es6 Modules_Babel Jest - Fatal编程技术网

Node.js 正在将jest传输到src目录之外

Node.js 正在将jest传输到src目录之外,node.js,reactjs,jestjs,es6-modules,babel-jest,Node.js,Reactjs,Jestjs,Es6 Modules,Babel Jest,我有一个monorepo设置,其中运行测试的项目试图从当前工作目录之外加载一个文件 目录结构 root mainApp src... library greetings.js 在hellies.js中 export const greetings = "hello World!" 每次我尝试从mainApp测试文件中的greetings.js导入时 //mainApp.test.js import {greetings} from "../../greetings.js";

我有一个monorepo设置,其中运行测试的项目试图从当前工作目录之外加载一个文件

目录结构

root
 mainApp
   src...
 library
   greetings.js
在hellies.js中

export  const greetings = "hello World!"
每次我尝试从mainApp测试文件中的greetings.js导入时

//mainApp.test.js
import {greetings} from "../../greetings.js";
我从控制台中的笑话中得到错误

Jest encountered an unexpected token
SyntaxError: Unexpected token export
以下url中的一个解决方案是将.babelrc添加到库文件夹

我有很多库,在每个库中添加.babelrc不是很干净。是否有其他/更好的方法来实现这一点

我甚至尝试在setUp.js文件中为jest添加以下内容

require('babel-register')({
  plugins: ['transform-es2015-modules-commonjs'],
  presets: ['env']
});
但玩笑还是失败了。任何帮助都将不胜感激


非常感谢

我遇到了同样的问题,发现了这个

将.babelrc重命名为babel.config.js并导出您的配置

babel.config.js

module.exports={}

在我的例子中,
babel jest
找不到它的配置文件,这可以通过在
jest配置中配置
transform
属性来解决

babel jest
显式设置
babel jest配置文件
属性的示例:

转换:{
“^.+\.[jt]sx?$”:[
'babel jest',{configFile:path.resolve(uu dirname,'config/babel.config.js')}
1] 
},

软件包中的jest配置和babel配置如何?