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

Issue using @swc-node/register and @swc/core #22146

Open
1 of 4 tasks
kris-vista opened this issue Mar 5, 2024 · 11 comments
Open
1 of 4 tasks

Issue using @swc-node/register and @swc/core #22146

kris-vista opened this issue Mar 5, 2024 · 11 comments
Assignees
Labels

Comments

@kris-vista
Copy link

kris-vista commented Mar 5, 2024

Current Behavior

To avoid getting wanings from nx whenever I run a build, I have installed @swc/core, @swc-node/register and @swc/helpers
No however, whenever I run a build of one of my projects inside my nx monorepo, I get the following error

  ERROR  failed to read input source map: failed to parse inline source map url
",u=a.length,l=(0,dr.basename)(e),f=(0,dr.extname)(e),p=n(e),y=l.slice(0,-f.length)+p+".map",E=u+y.length;if(t.substr(-E,u)===a)return t.slice(0,-E)+o;let g=u+encodeURI(y).length;return t.substr(-g,u)===a?t.slice(0,-g)+o:`${t}


Caused by:
    relative URL without a base
    at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\swc-0.272.4\src\lib.rs:385

The code that this error is referring to is located in .nx\cache\cloud\2402.27.3.hotfix2\index.js

While it says this is an error, the build appears to go through and complete successfully anyway

I have tried reinstalling my node_modules and removing the .nx folder but I get the same issue

I have tried creating a brand new nx monorepo with an empty app and this appears to build fine without this error.

Expected Behavior

The build should complete without any errors

GitHub Repo

https://github.com/kris-vista/nx-swc-issue

Steps to Reproduce

I am unable to reproduce this outside of my complex monorepo

Nx Report

Node   : 20.11.0
   OS     : win32-x64
   npm    : 10.2.4

   nx (global)        : 18.0.5
   nx                 : 18.0.4
   @nx/js             : 18.0.4
   @nx/jest           : 18.0.4
   @nx/linter         : 18.0.4
   @nx/eslint         : 18.0.4
   @nx/workspace      : 18.0.4
   @nx/angular        : 18.0.4
   @nx/cypress        : 18.0.4
   @nx/devkit         : 18.0.4
   @nx/eslint-plugin  : 18.0.4
   @nx/plugin         : 18.0.4
   @nrwl/tao          : 18.0.4
   @nx/web            : 18.0.4
   @nx/webpack        : 18.0.4
   typescript         : 5.3.3
   ---------------------------------------
   Community plugins:
   @auth0/auth0-angular           : 2.2.1
   @infragistics/igniteui-angular : 15.1.26
   @ngrx/component-store          : 17.0.1
   @ngrx/effects                  : 17.0.1
   @ngrx/entity                   : 17.0.1
   @ngrx/store                    : 17.0.1
   @ngrx/store-devtools           : 17.0.1
   devextreme-angular             : 23.1.6
   ng2-charts                     : 3.0.8
   nx-stylelint                   : 13.5.3
   ---------------------------------------
   Local workspace plugins:
         @vista/workspace-extensions

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@AgentEnder AgentEnder added the scope: misc Misc issues label Mar 5, 2024
@Bielik20
Copy link
Contributor

Bielik20 commented Mar 8, 2024

Experiencing exactly the same issue:

  ERROR  failed to read input source map: failed to parse inline source map url
";


Caused by:
    relative URL without a base
    at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.266.24/src/lib.rs:412

@ParriauxMaxime
Copy link

ParriauxMaxime commented Mar 8, 2024

Same issue here after upgrading nx to 18+.

nx run my_app:my_custom_executor --verbose

[NX CLOUD] Verifying current cloud bundle
[NX CLOUD] A local bundle currently exists:  {
  version: '2403.05.3.hotfix1',
  fullPath: '/home/user/Documents/project/.nx/cache/cloud/2403.05.3.hotfix1'
}
[NX CLOUD] Last verification was within the past 30 minutes, will not verify this time
[NX CLOUD] Done:  /home/user/Documents/project/.nx/cache/cloud/2403.05.3.hotfix1
  ERROR  failed to read input source map: failed to parse inline source map url
";


Caused by:
    relative URL without a base
    at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.273.15/src/lib.rs:385

It's seems to appear only when running custom executors.

nx report

 NX   Report complete - copy this into the issue template

Node   : 20.11.1
OS     : linux-x64
yarn   : 1.22.21

nx (global)        : 18.0.6
nx                 : 18.0.6
@nx/js             : 18.0.6
@nx/jest           : 18.0.6
@nx/linter         : 18.0.6
@nx/eslint         : 18.0.6
@nx/workspace      : 18.0.6
@nx/cypress        : 18.0.6
@nx/devkit         : 18.0.6
@nx/eslint-plugin  : 18.0.6
@nx/nest           : 18.0.6
@nx/node           : 18.0.6
@nx/plugin         : 18.0.6
@nx/react          : 18.0.6
@nx/storybook      : 18.0.6
@nrwl/tao          : 18.0.6
@nx/web            : 18.0.6
@nx/webpack        : 18.0.6
typescript         : 5.3.3
---------------------------------------
Community plugins:
@nx-plus/docusaurus : 15.0.0-rc.0
@nx/rspack          : 18.0.2
---------------------------------------
Local workspace plugins:
	 @project/nx-plugins

Also, this seems somewhat related to #21905

@montella1507
Copy link

Maybe related to #21377

Nx schematics adds these two packages, and after install, build of angular is broken.

image

@kris-vista
Copy link
Author

Same issue here after upgrading nx to 18+.

nx run my_app:my_custom_executor --verbose

[NX CLOUD] Verifying current cloud bundle
[NX CLOUD] A local bundle currently exists:  {
  version: '2403.05.3.hotfix1',
  fullPath: '/home/user/Documents/project/.nx/cache/cloud/2403.05.3.hotfix1'
}
[NX CLOUD] Last verification was within the past 30 minutes, will not verify this time
[NX CLOUD] Done:  /home/user/Documents/project/.nx/cache/cloud/2403.05.3.hotfix1
  ERROR  failed to read input source map: failed to parse inline source map url
";


Caused by:
    relative URL without a base
    at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.273.15/src/lib.rs:385

It's seems to appear only when running custom executors.

nx report

 NX   Report complete - copy this into the issue template

Node   : 20.11.1
OS     : linux-x64
yarn   : 1.22.21

nx (global)        : 18.0.6
nx                 : 18.0.6
@nx/js             : 18.0.6
@nx/jest           : 18.0.6
@nx/linter         : 18.0.6
@nx/eslint         : 18.0.6
@nx/workspace      : 18.0.6
@nx/cypress        : 18.0.6
@nx/devkit         : 18.0.6
@nx/eslint-plugin  : 18.0.6
@nx/nest           : 18.0.6
@nx/node           : 18.0.6
@nx/plugin         : 18.0.6
@nx/react          : 18.0.6
@nx/storybook      : 18.0.6
@nrwl/tao          : 18.0.6
@nx/web            : 18.0.6
@nx/webpack        : 18.0.6
typescript         : 5.3.3
---------------------------------------
Community plugins:
@nx-plus/docusaurus : 15.0.0-rc.0
@nx/rspack          : 18.0.2
---------------------------------------
Local workspace plugins:
	 @project/nx-plugins

Also, this seems somewhat related to #21905

I have some custome executors so that would make sense

@dsimon-dev
Copy link

Upgrading NX to 18.1.2 fixed this issue for me.

@kris-vista
Copy link
Author

I just upgraded to 18.1.2 and continue to get the same issue :(

@kris-vista
Copy link
Author

I have managed to reproduce the issue with a brand new nx workspace.
Basically I created an angular nx workspace with a single app
I then created a plugin following the example here: https://nx.dev/extending-nx/recipes/local-executors

The repo can be found here
https://github.com/kris-vista/nx-swc-issue

When you have it all set up, running the following command will generate the error
nx run first:echo

@metasaver
Copy link

I have managed to reproduce the issue with a brand new nx workspace. Basically I created an angular nx workspace with a single app I then created a plugin following the example here: https://nx.dev/extending-nx/recipes/local-executors

The repo can be found here https://github.com/kris-vista/nx-swc-issue

When you have it all set up, running the following command will generate the error nx run first:echo

Confirmed, exactly what I did too. Followed the instructions and got the same error, although the executor does work. Using version 18.2.1:

$ nx run test-plugin:echo --verbose
[NX CLOUD] Verifying current cloud bundle
[NX CLOUD] A local bundle currently exists: {
version: '2403.21.3.hotfix2',
fullPath: '/workspaces/monorepo/.nx/cache/cloud/2403.21.3.hotfix2'
}
[NX CLOUD] Last verification was within the past 30 minutes, will not verify this time
[NX CLOUD] Done: /workspaces/monorepo/.nx/cache/cloud/2403.21.3.hotfix2
ERROR failed to read input source map: failed to parse inline source map url
";

Caused by:
relative URL without a base
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.272.4/src/lib.rs:385

@JacobGardos
Copy link

JacobGardos commented Mar 31, 2024

After spending a couple hours debugging the nx bin, I've found a solution.

Simply install nx-cloud as a dependency.

npm install nx-cloud

I've tested it on Windows 11 and WSL via devcontainers and the problem seems to be fixed.

Here is a link to a basic working repository using a local plugin & executor:
https://github.com/JacobGardos/nx-swc-fix
(See README.md for instructions)

Let me know if this helps.


In case anyone is curious, here are some observations I made while debugging the nx run command using the Visual Studio Code JavaScript debugger. Hopefully, this can save you some time if you're attempting to implement a more permanent solution:

  1. If you don't already have nx-cloud installed, the problem can also be resolved by solely using the local cache. In other words, if you remove the nxCloudAccessToken from your nx.json or environment variables, the error seems to go away.

  2. If you don't have nx-cloud installed, when you debug the run command (e.g., nx run <project>:<target>), you'll notice that nx eventually calls a function inside of node_modules/nx/src/task-runner/run-command.js named loadTasksRunner(modulePath). From what I understand, this function checks to see if the nx-cloud package is installed. If it is, everything proceeds without issue. However, if nx-cloud is not installed, it seems to import a fallback package from its own directory at ../nx-cloud/nx-cloud-tasks-runner-shell. This might be where the error originates:

// node_modules/nx/src/tasks-runner/run-command.js  - line 261
function loadTasksRunner(modulePath) {
    try {
        const maybeTasksRunner = require(modulePath);
        // to support both babel and ts formats
        return 'default' in maybeTasksRunner
            ? maybeTasksRunner.default
            : maybeTasksRunner;
    }
    catch (e) {
        if (e.code === 'MODULE_NOT_FOUND' &&
            (modulePath === 'nx-cloud' || modulePath === '@nrwl/nx-cloud')) {
            return require('../nx-cloud/nx-cloud-tasks-runner-shell')
                .nxCloudTasksRunnerShell;
        }
        throw e;
    }
}

Hopefully, this helps. Let me know if I missed anything.


Nx Report For Windows 11 & WSL

Node   : 20.11.1
OS     : win32-x64
npm    : 10.2.4

nx (global)        : 18.2.1
nx                 : 18.2.1
@nx/js             : 18.2.1
@nx/jest           : 18.2.1
@nx/linter         : 18.2.1
@nx/eslint         : 18.2.1
@nx/workspace      : 18.2.1
@nx/devkit         : 18.2.1
@nx/eslint-plugin  : 18.2.1
@nx/nest           : 18.2.1
@nx/node           : 18.2.1
@nx/plugin         : 18.2.1
@nrwl/tao          : 18.2.1
@nx/web            : 18.2.1
@nx/webpack        : 18.2.1
nx-cloud           : 18.0.0
typescript         : 5.4.3
---------------------------------------
Local workspace plugins:
         @org/my-plugin
Node   : 20.11.1
OS     : linux-x64
npm    : 10.2.4

nx (global)        : 18.2.1
nx                 : 18.2.1
@nx/js             : 18.2.1
@nx/jest           : 18.2.1
@nx/linter         : 18.2.1
@nx/eslint         : 18.2.1
@nx/workspace      : 18.2.1
@nx/devkit         : 18.2.1
@nx/eslint-plugin  : 18.2.1
@nx/nest           : 18.2.1
@nx/node           : 18.2.1
@nx/plugin         : 18.2.1
@nrwl/tao          : 18.2.1
@nx/vite           : 18.2.1
@nx/vue            : 18.2.1
@nx/web            : 18.2.1
@nx/webpack        : 18.2.1
typescript         : 5.4.3
---------------------------------------
Local workspace plugins:
         @org/nuxt

@bretonics
Copy link

Can confirm this happened in a relatively new workspace, ~1 month or so, that has no Angular.

Connected workspace to Nx Cloud thinking it was the cache, but that solely did not fix the issue. It was not until I npm i nx-cloud as @JacobGardos suggested that the issue went away.

@blackholegalaxy
Copy link

We added nx-cloud as dependency without the issue being fixed. The error is still occuring since about 1 month.

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

No branches or pull requests