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

[ts-transform-paths] does not work for .js imports #27

Open
falkenhawk opened this issue Mar 23, 2020 · 7 comments
Open

[ts-transform-paths] does not work for .js imports #27

falkenhawk opened this issue Mar 23, 2020 · 7 comments

Comments

@falkenhawk
Copy link

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": "./src"
    // ...
  }
}

having e.g. src/helpers/time.js and in src/modules/index.ts:

import 'helpers/time';

it's not transformed to require('../helpers/time'); but left out as require('helpers/time')... which breaks execution

@zerkalica
Copy link
Owner

Probably solved in #28

@Borvik
Copy link

Borvik commented Mar 24, 2020

We are actually experiencing a similar issue but with a tsx file so I don't think this is limited to .js imports. We are using v1.7.13 of @zerollup/ts-transform-paths.

In our scenario we having the following in our tsconfig.json (our tsconfig is in a subfolder):

{
  "compilerOptions": {
    "paths": {
      "@components/*": ["src/components/*"],
      "@lib/*": ["src/lib/*"],
      "@pages/*": ["src/pages/*"],
      "@root/*": ["src/*"]
    },
    "plugins": [
      {
        "transform": "@zerollup/ts-transform-paths"
      }
    ],
    "baseUrl": "../",
    // ...
    }
}

In one of our files we have the following:

import handleGQLErrors from '@lib/handleGQLErrors';
import '@pages/users/view/tabs/notes/style.scss';

Which is getting transformed to the following js:

import handleGQLErrors from "../../../lib/handleGQLErrors";
import '@pages/users/view/tabs/notes/style.scss';

So we can see one of the import syntax in the same file is working, the other is not.

aside: The scss is intentional as a separate build process that requires this particular project process the scss there.

@falkenhawk
Copy link
Author

@zerkalica I'm sorry, but this does not seem to be fixed in 1.7.13 / #28

@zerkalica
Copy link
Owner

@Borvik, @falkenhawk , does 1.7.15 or 1.7.16 solves problem?

@Borvik
Copy link

Borvik commented Apr 6, 2020

I tried 1.7.16 and it did work. Thanks.

@IgorSzymanski
Copy link

https://github.com/IgorSzymanski/ts-transform-paths-bug-repro

I created a minimal reproduction. Still doesn't work for me. v. 1.7.17

@zerkalica
Copy link
Owner

@IgorSzymanski

add "tryLoadJs": true to plugin options
I create pr: https://github.com/IgorSzymanski/ts-transform-paths-bug-repro/pull/1/files

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

No branches or pull requests

4 participants