-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import not transpile with babel-jest #3202
Comments
Can you setup a repo with the case? |
I have same error. My configs: "dependencies": {
...
"babel-core": "6.24.0",
"babel-jest": "^19.0.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-polyfill": "6.23.0",
"babel-preset-es2015": "6.24.0",
"babel-preset-react": "6.23.0",
"babel-preset-stage-1": "6.22.0",
"enzyme": "2.8.0",
"jest": "^19.0.2",
"react-test-renderer": "15.4.2",
...
},
"jest": {
"browser": true
} Jest debug output
|
@brendonco you have |
I already add another environment to {
"ignore": [],
"env": {
"testing": {
"presets": ["es2015", "stage-1", "react", "flow"],
"plugins": ["lodash", "transform-runtime"]
},
"production": {
"presets": [["es2015", { "modules": false }], "stage-1", "react", "flow"],
"plugins": ["lodash", "transform-runtime"]
},
"development": {
"presets": [["es2015", { "modules": false }], "stage-1", "react", "flow"],
"plugins": ["lodash", "transform-runtime", "react-hot-loader/babel"]
}
}
} |
did you try calling it |
@SimenB I also run all test with "scripts": {
"test": "export NODE_ENV=testing && jest"
...
} |
I found this error after recent babel update. Fixed by removing default |
@max-mykhailenko try |
@DimitryDushkin I already do that and shown working |
@max-mykhailenko , what was your final solution? Getting a similar error with Jest. Repo at https://github.com/shahidjabbar/JestTest2.git |
@shahidjabbar Flow requires babel module Full version You should run flow with |
👍 |
Can anyone confirm that the |
Had the same problem. I had to remove my default presets and do it per environment basis like here #3202 (comment) @kmiyashiro you can name it like you want (normally test). Just specify the name of the environment in the babelrc the same as the NODE_ENV variable. |
I have the correct settings and it works most of the time. Randomly, after a rebuild, I will get this error when I try to run jest. The only thing that fixes it is to delete the jest cache tmp dir, which you can find by running this in node: console.log(require('os').tmpdir()) and then deleting |
my 2 cents if anyone has the same issue as me : |
To resolve the error: Unexpected token import, you need to configure your .babelrc file with presets for test environment. "env": {
"test": {
"presets":[
["es2015", { "modules": false }],
"react",
"stage-0"
],
"plugins": [
"transform-es2015-modules-commonjs",
"dynamic-import-node"
]
}
} |
@yogeshnikam, it didn't work. These are my files before changed: package.json
.babelrc
It was all working, but I decided to start use ts files and everything stop working. |
@rochapablo Did you tag the wrong person? |
@yangshun, my bad! Thanks. |
- enable module plugin of babel see: jestjs/jest#3202 - fix path to vue mapper
I put into my package.json:
and .babelrc:
|
@tachang thx! this did the trick for me! :) |
Of course, that makes sense. 😄 |
"Delightful JavaScript Testing" not when you run into this mess! |
@phyllisstein we're also using the new babel typescript parser, so I'm curious if you ever figured out a solution here |
Hey! Sorry I never updated this thread, I got pulled onto a different project at work and forgot about it. I've lost a little state about how I figured this out, but it turns out that you need to pass a Here's how we created the custom transformer: const { join, resolve } = require('path')
const { createTransformer } = require('babel-jest')
const packagePath = resolve('../')
const packageGlob = join(packagePath, '*')
module.exports = createTransformer({
babelrcRoots: packageGlob,
}) ...and then here's the Jest config snippet: module.exports = {
transform: {
'\\.tsx?$': '<rootDir>/spec/babel-transformer.js',
},
} This will force the transpiler to honor |
Post babel 7 upgrade, I started to run into this issue. I was able to fix it by ensuring that Before fix: yarn list babel-core
├─ babel-core@7.0.0-bridge.0
├─ babel-register@6.26.0
│ └─ babel-core@6.26.3
├─ jest-config@23.1.0
│ └─ babel-core@6.26.3
└─ jest-runtime@23.1.0
└─ babel-core@6.26.3 Fix (package.json + yarn): "resolutions": {
"babel-core": "7.0.0-bridge.0"
} After fix:
|
I'm having the same issue for transpiling the setupFiles, I'm using babel.config.js in a monorepo with yarn workspaces, what is the right way of doing this config? |
JS ecosystem makes me want to jump sometimes |
check this for more info #7359 |
@jackmahoney like out of window? |
One of the possible solution is to update to Jest 24, that uses Babel 7 for its parts With Jest 24 there is no conflicting issue with resolving modules between |
Related issue #5525 that provides more information on how Jest relies on Babel 7 or Babel 6 for backward comparability |
@sibelius did you ever get that sorted? I have the same setup |
Have you tried this? |
I'm having the same issue when I tried to test a monaco editor react component, it seems it doesn't find the package in node_modules when I run the test. |
FWIW, I've been beating my head against the wall for a day and a half with this issue. In my case, dropping back down to babel-jest v23.6.0 from v24.8.0 fixed it. Also, Adam (@etoxin) your comment made my day. 😆 └─┬ @vue/cli-plugin-unit-jest@3.8.0
├── babel-jest@23.6.0
└─┬ jest@23.6.0
└─┬ jest-cli@23.6.0
└─┬ jest-config@23.6.0
└── babel-jest@23.6.0 deduped |
Kubenetes says hold my beer. |
This is how I solved this problem. Add to your dependencies list in your package.json file
Your .babelrc in your root directory should look like this
Create jest.config.json file in you root directory and the content should look like this
Create a folder in your root directory called test and add setupTests.js file into it (test/setupTests.js). The content should look like this
In package.json, in the script object let you test look like this
Delete your node_module folder and reinstall it again Then do yarn test to run your test I hope this help |
I am currently seeing similar issues.
we use
I've done some of the changes suggested in this thread (like change the babel version to 3.6 or @phyllisstein babel-transformer without luck... i'm out of ideas... |
I also get the same error
|
this solved my problem: rename original error:
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
execute yarn test throw an exception below.
package.json
.babelrc
Any configuration I missed out?
The text was updated successfully, but these errors were encountered: