-
Notifications
You must be signed in to change notification settings - Fork 459
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
Docs: Troubleshoot import statement #2812
Conversation
TROUBLESHOOTING.md
Outdated
SyntaxError: Cannot use import statement outside a module | ||
|
||
### SOLUTION | ||
One of the node modules that is used doesn't need to be transpiled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls put a blank line between ### SOLUTION
and the description below
TROUBLESHOOTING.md
Outdated
|
||
```shell | ||
SyntaxError: Cannot use import statement outside a module | ||
20 | <script lang="ts"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strip out the stuffs related to Vue, in this case this line 54, 55
TROUBLESHOOTING.md
Outdated
``` | ||
In this case **some-module** is the problem. | ||
|
||
This module needs to be ignored in the transformation process. Add the following to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually transformIgnorePatterns
means:
I don't want to transform x,y,z modules.
However, the error SyntaxError: Cannot use import statement outside a module
has a different meaning.
It means
This module is not in the syntax which Jest can execute. You need to ask Jest to transform it.
The regex in your example has a !
which tells Jest to NOT ignore those modules in transformation step, which means Jest needs to transform those modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out and your explanation. I will change it.
Pull Request Test Coverage Report for Build 1115888734
💛 - Coveralls |
You would need to run lint-prettier :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Summary
When setting up a project with @vue/cli (https://github.com/vuejs/vue-cli) with version 4.5.13 with ts-jest I faced the problem that the test could not be executed for my component because one of the modules doesn't need to be transpiled.
I found this answer after searching for a long time on the web and therefore thought it should be added to the documentation of the project.
Test plan
There are no changes in the code. In can be tested as follows:
vue create project
npm install --save vue vue-class-component
HelloWorld.vue
component:npm run test:unit
and verify the error message.jest.config.js
as following:Does this PR introduce a breaking change?
Other information