Skip to content

ignored() bug: ESM loader will try to compile .cjs, .mjs, and other unexpected file extensions #1098

@cspotcode

Description

@cspotcode

ESM loader uses our current ignored() implementation to determine if it should transform a file. This only excludes the .js and .jsx file extensions as needed. This worked fine with our CommonJS loader, because we knew we were only registered for the .ts, .tsx, and maybe .js and .jsx extensions.

The ESM loader is different, so it's asking ignore() about .mjs files. (maybe other extensions too?)

We need to update the ignored() implementation to include rather than exclude file extensions so that we only transform the same files that tsc can transform.

ts-node/src/index.ts

Lines 837 to 845 in ce7c323

const ignored = (fileName: string) => {
if (!active) return true
const relname = relative(cwd, fileName)
if (!config.options.allowJs) {
const ext = extname(fileName)
if (ext === '.js' || ext === '.jsx') return true
}
return !isScoped(relname) || shouldIgnore(relname)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions