Running Jest tests for Typescript ESM modules
typescript, programming, jest, vs code, ESM
It took me 2:30 hours to set this up and document it, it's incredibly tedious 😅
💡 If you're going to create a new npm project, take a look at my npm-package-template
package.json
configuration
package.json
configurationAdd
jest
configuration information topackage.json
You don't need to use
jest.config.js
We fix the mandatory
import.js
rule that comes fromESM
with themoduleNameMapper
settingWe activate
esm
usage for typescript codes with^.+\\\\.ts$
launch.json
configuration for VSCode
launch.json
configuration for VSCodeError Notes
SyntaxError: Cannot use import statement outside a module
We should use
node
withexperimental-vm-modules
argument for Jest usage, otherwise we get an error
Plugin Recommendation
References
Jest Typescript with ES Module in node_modules error - Must use import to load ES Module:
PreviousTypescript ESM icin Jest calistirmakNextConverting Instagram saved_collections.json file to csv file and importing it to notion
Last updated