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

Unable to find module with tsconfig-paths when using esm: tsconfig-paths is incompatible with native ESM #1375

Closed
kikyouink opened this issue Jun 20, 2021 · 5 comments

Comments

@kikyouink
Copy link

kikyouink commented Jun 20, 2021

Expected Behavior

tsconfig-paths can read my alias in tsconfig.json

Actual Behavior

tsconfig-paths can't read my alias in tsconfig.json

Steps to reproduce the problem

i use nodemon,here is my modemon.json

{
    "watch": ["*"],
    "ext": "ts,js,json",
    "exec": "node --loader ts-node/esm -r tsconfig-paths/register ./src/server/server.ts"
}

Minimal reproduction

just run nodemon

Specifications

  • ts-node version: 10.0.0
  • node version: 16.0.0
  • TypeScript version: 4.3.2
  • tsconfig.json, if you're using one:
{
    "ts-node": {
        "transpileOnly": true,
        "files": true,
    },
    "compilerOptions": {
        "target": "ESNext",
        "module": "ESNext",
        "moduleResolution": "node",
        "strict": true,
        "jsx": "preserve",
        "sourceMap": true,
        "resolveJsonModule": true,
        "noImplicitThis": true,
        "noEmit": true,
        "removeComments": true,
        "esModuleInterop": true,
        "lib": ["ESNext", "dom"],
        "baseUrl": ".",
        "paths": {
            "@/*": ["src"],
            "@components/*": ["src/components/*"],
            "@config/*": ["src/config/*"],
            "@hooks/*": ["src/hooks/*"],
            "@views/*": ["src/views/*"],
            "@utils/*": ["src/utils/*"]
        }
    },
    "include": ["/**/*.ts", "/**/*.d.ts", "/**/*.vue"]
}
  • Operating system and version: macos big sur 11.4
  • If Windows, are you using WSL or WSL2?:
@jeroen-hoekstra
Copy link

Experiencing the same issue. It works in version 9.1.1. Stopped working in version 10.0.0

@kikyouink
Copy link
Author

Experiencing the same issue. It works in version 9.1.1. Stopped working in version 10.0.0

Unfortunately i tried 9.1.1,doesnt work too

@cspotcode
Copy link
Collaborator

cspotcode commented Jun 23, 2021 via email

@kikyouink
Copy link
Author

tsconfig-paths does not support native ESM. Ts-node 9.1.1 has a limitation where it will allow you to (silently, accidentally) use CommonJS when you think you are using native ESM. Projects that are accidentally taking advantage of this behavior may find that things break on ts-node 10, since ts-node 10 fixes this flaw. When ts-node 9 silently runs your code as CommonJS, and tsconfig-paths is compatible with CommonJS, then things work. Fixes are either: - add native ESM support to tsconfig-paths - use CommonJS

On Wed, Jun 23, 2021, 2:59 AM SAI @.***> wrote: Experiencing the same issue. It works in version 9.1.1. Stopped working in version 10.0.0 Unfortunately i tried 9.1.1,doesnt work too — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#1375 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC35OEVKJAQRGRQYWK3RC3TUGA5VANCNFSM47AALGWQ .

thanks a lot , i think i'll use commonjs

@FossPrime
Copy link

You could also, bend your code to support relative imports... You may have to move it around if you use unpredictable, and that may break tests, linters transpilers ... I've just been living without typescript linting where I can't make it work yet.

@cspotcode cspotcode changed the title Unable to find module with tsconfig-paths when using esm Unable to find module with tsconfig-paths when using esm: tsconfig-paths is incompatible with native ESM Apr 21, 2022
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

4 participants