Skip to content
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

How to use nyc with TypeScript and ESM? #1537

Closed
bennycode opened this issue Oct 26, 2023 · 1 comment
Closed

How to use nyc with TypeScript and ESM? #1537

bennycode opened this issue Oct 26, 2023 · 1 comment

Comments

@bennycode
Copy link

bennycode commented Oct 26, 2023

Hi there, I moved my TypeScript codebase from CommonJS to ESM (using "type": "module" in my package.json file). My nyc.config.json looks like this:

{
  "all": false,
  "check-coverage": false,
  "exclude": ["**/*.d.ts", "**/*.test*.ts", "**/index.ts", "**/demo/**/*"],
  "extension": [".ts"],
  "include": ["src/**/*.ts"],
  "per-file": false,
  "reporter": ["text-summary"],
  "require": ["ts-node/esm"]
}

According to the docs of ts-node, I have to switch from --require ts-node/register to --loader ts-node/esm.

I tried to change "require": ["ts-node/esm"] to "loader": ["ts-node/esm"] in my nyc.config.json but I am getting this error:

Must use import to load ES Module

Can you help me with a code recipe to solve that? Currently I am starting my tests with Jasmine without nyc: ts-node-esm ./node_modules/.bin/jasmine --config=jasmine.json.

Best,
Benny

@bennycode
Copy link
Author

Today I learnt that c8 supports .nycrc.json config files, so I could easily switch to c8 and make it working with TypeScript, ESM & Jasmine:

{
  "scripts": {
    "test": "c8 --config=.nycrc.json ts-node-esm ./node_modules/.bin/jasmine --config=jasmine.json"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant