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

@swc-node/register broken imports #729

Open
wszydlak opened this issue Sep 6, 2023 · 10 comments
Open

@swc-node/register broken imports #729

wszydlak opened this issue Sep 6, 2023 · 10 comments

Comments

@wszydlak
Copy link

wszydlak commented Sep 6, 2023

According to nrwl/nx#18985 (comment) - last change in @swc-node/register which added baseUrl to tsconfig broke nx generators, eg:

// /path/to/file.ts
import { something } from  './subdir';

// /path/to/subdir/index.ts
export const something = 1;

This throws an error: Cannot find module './subdir/index.js'

At least such a change should not be added as a bugfix, cause it broke bacward compatibility.

This worked great in @swc-node/register@1.6.6 and has been broken in 1.6.7

@artamonovtech
Copy link

artamonovtech commented Sep 6, 2023

I have the same problem with 1.6.7 version.

@MrRefactoring
Copy link

Me too

@kurt-west
Copy link

I did some debugging and found the new baseUrl variable that was added in 1.6.7 is to blame. If I comment out that line my project builds as normal; it would be nice if you (@wszydlak , @artamonovtech, @MrRefactoring) could try the same to confirm.

I manually tried everything relative and absolute path I could think of and nothing seemed to work, which leads me to believe this is an issue with this library vs. nx.

@MrRefactoring
Copy link

@kurt-west not helped for me :(

@kurt-west
Copy link

@MrRefactoring interesting... thanks for giving it a try.

@wszydlak
Copy link
Author

wszydlak commented Sep 13, 2023

I can confirm that removing line: https://github.com/swc-project/swc-node/blob/master/packages/register/read-default-tsconfig.ts#L123 helps.

Also confirm that changing this line also helps for nx case:

-baseUrl: resolve(options.baseUrl ?? './'),
+baseUrl: options.baseUrl != null ? resolve(options.baseUrl): undefined,

However i think that baseUrl should not be manipulated on swc side, if user needs to have absolute paths, then probably swc could give an option to register tsconfig transformer, where the user could modify config.

@wszydlak
Copy link
Author

wszydlak commented Oct 5, 2023

@kurt-west some status? Maybe some plans to restore previous behavior?

@kurt-west
Copy link

@wszydlak - sorry I'm not a maintainer or contributor to this project and know very little about swc in general. I just ran into the issue at it related to nx and did some investigating. My ping to the group was to confirm everyone was seeing similar behavior in the hopes it would be an easy fix for the swc team.

@wszydlak
Copy link
Author

@Brooooooklyn any chances to get this work?

@Tom910
Copy link

Tom910 commented Nov 22, 2023

After upgrade version I found similar an issue too:

import fs from 'fs';
const {access} = fs.promises;

in this case fs has the undefined value and error TypeError: Cannot read properties of undefined. In my cases option "esModuleInterop": true missed after upgrade the version.

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

No branches or pull requests

5 participants