Skip to content

verbatimModuleSyntax is ignored, so unused imports and their side effects are removed #798

Closed

Description

@fengmk2

Reproduction

// tsconfig.json
{ "compilerOptions": { "verbatimModuleSyntax": true } }
// package.json
{ "type": "module" }
// polyfill.ts
console.log('polyfill.ts evaluated');
export const installed = true;
// main.ts
import { installed } from './polyfill.ts';
console.log('main.ts');
$ node --import @oxc-node/core/register main.ts
main.ts

$ node main.ts
polyfill.ts evaluated
main.ts

With verbatimModuleSyntax, TypeScript keeps every import that is not marked type, and Node.js' own type stripping does the same. oxc-node removes installed because it is unused, so polyfill.ts never runs.

Environment: @oxc-node/core 0.1.4, Node.js 22.18.0, 24.21.0, and 26.5.0, macOS arm64.

Cause

only_remove_type_imports is hard-coded to false (src/lib.rs#L717).

Suggested fix

only_remove_type_imports: compiler_options
    .and_then(|c| c.verbatim_module_syntax)
    .unwrap_or(false),

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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions