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

failed to import TS file from node_modules on Linux & Mac #990

Closed
TechQuery opened this issue Mar 26, 2020 · 8 comments · Fixed by #970
Closed

failed to import TS file from node_modules on Linux & Mac #990

TechQuery opened this issue Mar 26, 2020 · 8 comments · Fixed by #970

Comments

@TechQuery
Copy link

TechQuery commented Mar 26, 2020

Expected Behavior

I want to import everything (including TS source codes in node_modules/) :

register({
    ignore: [],
    compilerOptions: { module: 'CommonJS' }
});

https://github.com/EasyWebApp/MarkCell/blob/7b43ea0/source/File.ts#L26-L29

Actual Behavior

OS result
Windows everything is OK
Linux TypeError: Unable to require file: node_modules/xxx/source/yyy.tsx
Mac TypeError: Unable to require file: node_modules/xxx/source/yyy.tsx

error on Linux

https://travis-ci.com/github/EasyWebApp/mark-wiki/builds/155135722

error on Mac

image

Steps to reproduce the problem

git clone https://github.com/EasyWebApp/mark-wiki.git
cd mark-wiki/
npm install
npm run build

Minimal reproduction

TypeStrong/ts-node-repros#1

Specifications

  • ts-node version: 8.8.1
  • TypeScript version: 3.8.3
  • tsconfig.json, if you're using one:
{
    "compilerOptions": {
        "module": "ESNext",
        "moduleResolution": "Node",
        "resolveJsonModule": true,
        "experimentalDecorators": true,
        "jsx": "react",
        "jsxFactory": "createCell",
        "target": "ES5",
        "lib": ["ES2019", "DOM"]
    },
    "include": ["source/**/*"]
}
  • node version: 12.16.1
  • If Windows, are you using WSL or WSL2?: No
@cspotcode
Copy link
Collaborator

This sounds like an issue that will be fixed by #970

The TypeScript compiler refuses to compile files with node_modules in their path, because it classified these files as "external." #970 talks about how we can implement our own classification logic.

@TechQuery
Copy link
Author

@cspotcode But why Windows works? The difference of File System?

@cspotcode
Copy link
Collaborator

Not sure, though that does seem strange.

Could be an issue with Windows paths using backslashes instead of forward slashes, or an issue with Windows being case-insensitive.

Can you simplify your reproduction to the bare minimum? I think you can trigger the problem with only 4 files, for example: tsconfig.json, package.json, index.ts, and node_modules/foo/bar.ts.

@TechQuery
Copy link
Author

@cspotcode reproduction created, but GitHub Actions doesn't run...

@cspotcode
Copy link
Collaborator

Thanks! The Github Actions is still experimental, I may have made a mistake. I will take a look.

@cspotcode
Copy link
Collaborator

I tried running and it succeeds; no errors. Can you take another look?

I also fixed the Github Actions, so if you merge the latest master into your branch and push again, it should run.

@TechQuery
Copy link
Author

@cspotcode I don't know why the minimal reproduction is OK...

@cspotcode
Copy link
Collaborator

@TechQuery I suspect this was working on Windows due to the bug fixed by #997, which was released in v8.9.0

We were not rigorously normalizing Windows paths, so in some codepaths, they had \ instead of /. Probably, these backslash paths were not being classified as "external" by the compiler, so you were able to require them.

This should be fixed by #970 and looks like the same underlying issue as #876.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants