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

TSConfig Paths: error with allowJs #79

Closed
yoursunny opened this issue May 27, 2020 · 7 comments · Fixed by #80
Closed

TSConfig Paths: error with allowJs #79

yoursunny opened this issue May 27, 2020 · 7 comments · Fixed by #80

Comments

@yoursunny
Copy link
Contributor

Environment: Node 14.3.0 on Windows 10 version 2004

package.json

{
  "private": true,
  "type": "module",
  "scripts": {
    "build": "tsc --noEmit",
    "dev": "node --loader @k-foss/ts-esnode --experimental-specifier-resolution=node proj/main.ts"
  },
  "devDependencies": {
    "@k-foss/ts-esnode": "^1.5.0",
    "typescript": "^3.9.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "module": "ESNext",
    "target": "ESNext",
    "moduleResolution": "Node",
    "baseUrl": ".",
    "paths": {
      "hello": ["./demo.js"]
    }
  }
}

proj/main.ts

import { f } from "hello";
console.log(f());

demo.js

export function f() { return 1; }

npm run build completes successfully, which means that the TypeScript is valid.

npm run dev fails with the following error:

(node:16144) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/C:/Users/sunny/Documents/code/tsesnodebug/proj/demo.js' imported from C:\Users\sunny\Documents\code\tsesnodebug\proj\main.ts
Did you mean to import ../../demo.js?
    at finalizeResolution (internal/modules/esm/resolve.js:269:11)
    at moduleResolve (internal/modules/esm/resolve.js:658:10)
    at defaultResolve (internal/modules/esm/resolve.js:748:11)
    at resolve (file:///C:/Users/sunny/Documents/code/tsesnodebug/node_modules/@k-foss/ts-esnode/out/dist/index.js:56:12) 
    at Loader.resolve (internal/modules/esm/loader.js:97:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
    at link (internal/modules/esm/module_job.js:41:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
@yoursunny
Copy link
Contributor Author

After this line, insert:

        context.parentURL = parentURL;

would solve this problem.
This does not break any test case, but it could break JavaScript applications.

@EntraptaJ
Copy link
Member

After this line, insert:

        context.parentURL = parentURL;

would solve this problem.
This does not break any test case, but it could break JavaScript applications.

I know exactly what the issue is, I'm forcing there to be a search for typescript extensions overriding the fact that it's not relative although I'm not sure how I can solve it. Can you try replicating the test but the path file not have the dot JS ending like via in the TS config remove the .js

@EntraptaJ
Copy link
Member

After this line, insert:

        context.parentURL = parentURL;

would solve this problem.
This does not break any test case, but it could break JavaScript applications.

I know exactly what the issue is, I'm forcing there to be a search for typescript extensions overriding the fact that it's not relative although I'm not sure how I can solve it. Can you try replicating the test but the path file not have the dot JS ending like via in the TS config remove the .js

wish I saw this like 2 minutes ago I just shut down everything for the night and I was just browsing GitHub on my phone.

@EntraptaJ
Copy link
Member

I see the issue. It's because my appended path isn't being passed to // Let Node.js handle all other specifiers. return defaultResolve(specifier, context, defaultResolve);
The reason it works for TS is because of my super def not a hack \s method for "finding/resolving" .ts/.tsx/.js/.jsx files without an extension.

@EntraptaJ
Copy link
Member

I SEE THE LIGHT!!! So this fix ain't so easy, I see now that I also fucked up with my "parsing" of the paths. Of course after I've been awake for 12 hours I see the proper way, but not during the early day... FUCK!

@EntraptaJ EntraptaJ linked a pull request May 27, 2020 that will close this issue
@yoursunny
Copy link
Contributor Author

wish I saw this like 2 minutes ago I just shut down everything for the night and I was just browsing GitHub on my phone.

Sleep, gym, and food are more important than coding. You didn't have to fix the bug overnight...

@EntraptaJ
Copy link
Member

wish I saw this like 2 minutes ago I just shut down everything for the night and I was just browsing GitHub on my phone.

Sleep, gym, and food are more important than coding. You didn't have to fix the bug overnight...

It was either this or watch TV, I ran out of the pills that allow me to sleep, so I was unable to fall asleep till 5AM, so I figured I might as well be productive. I have a horrible work/sleep/hobby balance.

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

Successfully merging a pull request may close this issue.

2 participants