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

js:swc compiler with non-watch mode exits with TypeError: The "id" argument must be of type string. Received undefined #12344

Closed
calvinl opened this issue Sep 30, 2022 · 2 comments · Fixed by #12345

Comments

@calvinl
Copy link
Contributor

calvinl commented Sep 30, 2022

Current Behavior

When using the node executor with a buildTarget using @nrwl/js:swc and turning off watch mode, the following error is produced:

TypeError: The "id" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:371:5)
    at validateString (node:internal/validators:120:11)
    at Module.require (node:internal/modules/cjs/loader:998:3)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/foo/node_modules/@nrwl/js/src/executors/node/node-with-require-overrides.js:23:1)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

This works with watch mode on.

Expected Behavior

This error should not show up with watch mode turned off.

Debugging

It appears that the error is coming from here:

const Module = require('module');
const originalLoader = Module._load;
const mappings = JSON.parse(process.env.NX_MAPPINGS);
const keys = Object.keys(mappings);
const fileToRun = process.env.NX_FILE_TO_RUN;

Where process.env.NX_FILE_TO_RUN is undefined.

Tracing this leads to the compileSwc (without watch mode) function, which does not return an outfile property. My guess is that this was not meant to be executed since it's used for building a library?

return { success: !hasErrors && isCompileSuccess };

Since outfile is not defined, the node executor tries to require(undefined), causing this error.

That said, if using @nrwl/js:tsc this works perfectly fine with watch mode turned off. So in line with that, I believe the swc compilation option should still work for this use case.

Resolution

It can be fixed quite simply by adding the following

return { 
  success: !hasErrors && isCompileSuccess,
  outfile: normalizedOptions.mainOutputPath
};

Steps to Reproduce

See reproducible example in this repository: https://github.com/calvinl/nx-swc-error-example

Failure Logs

See above

Environment

   Node : 16.14.2
   OS   : darwin arm64
   npm  : 8.5.0

   nx : 14.8.2
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.8.2
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 14.8.2
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.8.2
   @nrwl/js : 14.8.2
   @nrwl/linter : 14.8.2
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 14.8.2
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 14.8.2
   @nrwl/workspace : 14.8.2
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
@calvinl
Copy link
Contributor Author

calvinl commented Oct 3, 2022

Anything I can do to help get this through the pipeline? I've had to resort to copying the @nrwl/js package as a local executor in my workspace to get this working.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants