-
Notifications
You must be signed in to change notification settings - Fork 789
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
SyntaxError: Cannot use import statement outside a module #2178
Comments
I've been running in to this one, too. Jest doesn't work with ES modules (see jestjs/jest#9292, jestjs/jest#9622, and jestjs/jest#8751), so at the moment, it will bail on any code it encounters with an From what I can gather, Stencil is compiling the Typescript component file, then passing that code to Jest. What seems to be going wrong is that dependencies of the component file are not transpiled, so any In theory, if the spec tests were to use the full CJS output for a given component, it would work. In practice, I'm not sure what needs to change. It doesn't seem like something fixable just by changing the jest parameters... but maybe I'm missing something. |
I am facing same issue currently. Can you please suggest any workaround or fix for this? Thanks |
Me too! I am seeing the same question |
Hi @shirinrpatel @raind33, maybe this can help you jestjs/jest#9395 (comment) |
I'm running into this issue too. It started happening in 1.17.0 (fine in 1.16.5) which points to the upgrade of [email protected] as the smoking gun. In my case, one of my stencil components imports the If I I haven't yet found a way to coerce jest to compile the |
I've found a fix that works for me although this only became an issue after upgrading to 1.17.x. So if you're on 1.17.x and you're getting this issue when running jest test you should be able to work around the issue by adding the following testing: {
...
moduleFileExtensions: [
'ts',
'tsx',
'js',
'mjs',
'jsx',
'json',
'd.ts'
]
} |
Thanks @Kiliandeca. It was working for me by adding something like
|
We're facing the same problems. Any Any working solution or at least a workaround? |
Just for those that may arrive at this page in the future. I was getting this error because somehow a whole bunch of compiled JS files got left in my source. So the tests were running on the TS file (working) and then on the generated JS file which threw this error. Solution was to remove generated js files (something like |
Having the same issue. Have tried adding all the possible permutations of below code and it has not worked. (adding in stencil.config.ts)
|
A solution that worked for me was to add this in // Can simply extend the list if we ever consume more esModules.
const esModules = [
// dependencies of esm packages
].join('|');
export const config: Config = {
//...
transform: {
'^.+\\.(ts|tsx|js|jsx|css)$': "@stencil/core/testing/jest-preprocessor"
},
transformIgnorePatterns: [`/node_modules/(?!${esModules})`], |
Let's consolidate this effort to enable support for ESM in Stencil unit tests within #3230. Thanks for all your comments. |
Stencil version:
I'm submitting a:
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior:
I'm using a lib named Elix (https://component.kitchen/elix) and it works for npm start.
But I get an ERROR on npm-test:
Expected behavior:
npm test doesn't fail
Steps to reproduce:
Create Stencil a default Project with "npm init stencil" and select app
Related code:
npm install elix
add to any of stencil component. E.g. app-home
import 'elix/define/Tabs'
run
npm test
// insert any relevant code here
Other information:
I've searched throught stenciljs and jest documentation and tried to solve it by adding
to stencil.config.ts
The text was updated successfully, but these errors were encountered: