Requires ESM module transformation
See original GitHub issueWhen trying to import this into a @nrwl/nx
configured workspace I get the following error:
● 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.
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.
• 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:
/Volumes/MacOS-Data/Home/wsedlacek/Devolpement/angular/brandingbrand/node_modules/rxjs/dist/types/internal/scheduler/AsyncScheduler.d.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { Scheduler } from '../Scheduler';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (../../../node_modules/jest-runtime/build/index.js:1679:14)
at Object.<anonymous> (../../../node_modules/@hirez_io/observer-spy/src/fake-time.ts:2:1)
It appears that using this internal rxjs
import results in an invalid import in some enviorments.
https://github.com/hirezio/observer-spy/blob/00ee48a862831883a6ee488495fb83112bb9873b/src/fake-time.ts#L2
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
Using require to load an ES module is not supported because ES modules have asynchronous execution. Instead, use import() to load an ES...
Read more >How to use ESM on the web and in Node.js - ByteofDev
ESM (ECMAScript Modules) is a modern module format with many ... Obviously, CommonJS requires transformation and therefore can add some code ...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
how to find other modules which that file imports; and how to transform that ... fail in ES modules because relative import paths...
Read more >How to transpile into commonjs the import of an ESM module
Error [ERR_REQUIRE_ESM]: require() of ES Module ... I found babeljs.io/docs/en/babel-plugin-transform-modules-commonjs, but it seems like ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @wSedlacek and @kylecordes ! Sorry about the delay, had a busy month and half I’m planning to work on this issue this week, will update
I think I managed to solve it Please update to the latest version (2.1.1) and let me know if fakeTime works the same for you