Skip to content

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

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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