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";
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".
What happened?
I tried to import some types from
@unified-latex/unified-latex-types
in my TypeScript project whose tsconfig has"module": "Node16"
, howevertsc
saidNamespace '"/path/to/node_modules/@unified-latex/unified-latex-types/index"' has no exported member 'XXX'
.Why this happened?
tsc
reports following errors: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
How to reproduce
Workaround
Currently, there is no workaround for this issue. It cannot be used in the project whose tsconfig specified
"module": "node16"
or"module": "nodenext"
.