You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Install and configure nvm, if you haven't already.
Run the commands from the README:
nvm use stable
yarn jest test.ts
nvm use lts/fermium
yarn jest test.ts
Expected behavior
Successful test results in both Node stable (16.x) and Node.js LTS/fermium (14.x).
Actual behavior
When jest-transform processes the test file, it detects that Node.js 16.x supports the ??= operator, so it doesn't transform it, and it caches the resulting transformed file. When Jest is rerun under Node 14.x, jest-transform reuses that cache, even though it's no longer valid, resulting in the following error:
yarn run v1.22.17
$ /Users/joshkel/tmp/node_modules/.bin/jest test.ts
FAIL ./test.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
describe("test", () => {
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/joshkel/tmp/test.ts:6
a ??= 2;
^^^
SyntaxError: Unexpected token '??='
Additional context
Brainstorming possible solutions:
jest-transform could include the Node version (full version? major version?) when determining its cache directory. (Would that suffice, or are there other factors that go into transformed files that are also not considered?)
When Jest hits a "Jest encountered an unexpected token" error, it could decide that the jest-transform results must be invalid and clear the cache.
When Jest hits a "Jest encountered an unexpected token" error, its "Here's what you can do:" guidance could provide instructions on clearing the jest-transform cache.
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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
Version
27.4.2
Steps to reproduce
yarn install
Expected behavior
Successful test results in both Node stable (16.x) and Node.js LTS/fermium (14.x).
Actual behavior
When jest-transform processes the test file, it detects that Node.js 16.x supports the
??=
operator, so it doesn't transform it, and it caches the resulting transformed file. When Jest is rerun under Node 14.x, jest-transform reuses that cache, even though it's no longer valid, resulting in the following error:Additional context
Brainstorming possible solutions:
Environment
The text was updated successfully, but these errors were encountered: