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

Cannot import any types in unified-latex-types with "module": "Node16" #72

Open
pddg opened this issue Feb 11, 2024 · 1 comment
Open

Comments

@pddg
Copy link
Contributor

pddg commented Feb 11, 2024

What happened?

I tried to import some types from @unified-latex/unified-latex-types in my TypeScript project whose tsconfig has "module": "Node16", however tsc said Namespace '"/path/to/node_modules/@unified-latex/unified-latex-types/index"' has no exported member 'XXX'.

Why this happened?

tsc reports following errors:

node_modules/@unified-latex/unified-latex-types/index.d.ts:1:15 - error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

1 export * from "./libs/ast-types";
                ~~~~~~~~~~~~~~~~~~

node_modules/@unified-latex/unified-latex-types/index.d.ts:2:15 - error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

2 export * from "./libs/type-guard";
                ~~~~~~~~~~~~~~~~~~~

node_modules/@unified-latex/unified-latex-types/index.d.ts:3:15 - error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

3 export * from "./libs/info-specs";

node16 and nodenext do not support importing the extensionless relative path feature.
https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext-1

Environment

  • macOS 14.3
  • Node JS v20.11.0
  • Typescript 5.3.3

How to reproduce

mkdir repro
cd repro

# Create package.json
cat << EOF > package.json
{
  "name": "unified-latex-import-issue",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "build": "tsc"
  },
  "devDependencies": {
    "@unified-latex/unified-latex-types": "1.6.0",
    "typescript": "5.3.3"
  }
}
EOF

# Create tsconfig.json with `module: Node16`
cat << EOF > tsconfig.json
{
    "compilerOptions": {
        "target": "ESNext",
        "module": "Node16",
        "moduleResolution": "Node16",
        "outDir": "./dist",
    },
    "exclude": ["node_modules"],
    "include": ["**/*.ts"]
}
EOF

# Add sample script to compile
cat << EOF > main.ts
import type * as Ast from "@unified-latex/unified-latex-types";

function isRoot(node: Ast.Node): node is Ast.Root {
  return node.type === "root";
}
EOF

# Install depends and try to compile with tsc
npm install
npm run build

Workaround

Currently, there is no workaround for this issue.
It cannot be used in the project whose tsconfig specified "module": "node16" or "module": "nodenext".

@siefkenj
Copy link
Owner

I will think about this one. For now, you should be able to use moduleResolution: "Bundler" to import the types.

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

2 participants