小编Kha*_*794的帖子

getting jest to transpile outside of src directory

I have a monorepo setup where the project running tests is trying to load a file from outside the current working directory.

Directory structure

root
 mainApp
   src...
 library
   greetings.js
Run Code Online (Sandbox Code Playgroud)

Within greetings.js

export  const greetings = "hello World!"
Run Code Online (Sandbox Code Playgroud)

Every time I try to import from greetings.js in my mainApp test files

//mainApp.test.js
import {greetings} from "../../greetings.js";
Run Code Online (Sandbox Code Playgroud)

I get error from Jest in console

Jest encountered an unexpected token
SyntaxError: Unexpected token export
Run Code Online (Sandbox Code Playgroud)

One solution in the following url is to add …

node.js reactjs jestjs babel-jest es6-modules

5
推荐指数
1
解决办法
2055
查看次数

标签 统计

babel-jest ×1

es6-modules ×1

jestjs ×1

node.js ×1

reactjs ×1