nx: [@nwrl/js] TypeError [ERR_INVALID_ARG_TYPE]: The "to" argument must be of type string. Received undefined
Current Behavior
A specific package with one dependency always fail even the build from itself and the dependency are successful.
Expected Behavior
Don’t fail and stop the run.
Github Repo
No response
Steps to Reproduce
- After realize my code was actually fine and completely built, I went verbose mode
- I found an error being thrown at
/node_modules/@nrwl/js/src/utils/inline.js:171:48 - This line is the built version of this source code, which naively assume that result is always a valid key of
inlinedDepsDestOutputRecord, and it’s value is a string
const importPath = `"${relative(
dirPath,
inlinedDepsDestOutputRecord[result]
)}"`;
- I put a
console.log, which it’s output can be found below, and confirmed thatresultis actuallyundefined
I don’t know how to reproduce it without exposing private code, I didn’t found anything special different from any other file or package in this project that could explain such behavior.
Since I don’t quite understand the core of this tool, so I can’t explain it.
I’m sincerely sorry, but I’ve already lost many many hours trying to understand what was wrong with my code (that works and build perfectly fine outside nx workspace) to spend many more trying to figure how to reproduce it without changing the tool itself to test.
Nx Report
> NX Report complete - copy this into the issue template
Node : 16.17.1
OS : darwin x64
npm : 8.19.2
nx : 15.4.2
@nrwl/angular : Not Found
@nrwl/cypress : 15.4.2
@nrwl/detox : Not Found
@nrwl/devkit : 15.4.2
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.4.2
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.4.2
@nrwl/js : 15.4.2
@nrwl/linter : 15.4.2
@nrwl/nest : 15.4.2
@nrwl/next : Not Found
@nrwl/node : 15.4.2
@nrwl/nx-cloud : 15.0.2
@nrwl/nx-plugin : 15.4.2
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/rollup : 15.4.2
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : 15.4.2
@nrwl/webpack : 15.4.2
@nrwl/workspace : 15.4.2
@nrwl/vite : Not Found
typescript : 4.9.4
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
@wanews/nx-esbuild: 0.26.1
@wanews/nx-typescript-project-references: 0.21.0
Failure Logs
nx run utils:build
Compiling TypeScript files for project "utils"...
Done compiling TypeScript files for project "utils".
{
dirPath: '[project_root_dir]/dist/packages/libs/utils/src',
importRegex: /(?:)/g,
inlinedDepsDestOutputRecord: {},
filePath: '[project_root_dir]/dist/packages/libs/utils/src/address.d.ts',
matched: '',
result: '',
value: undefined
}
node:internal/errors:477
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "to" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:387:5)
at validateString (node:internal/validators:121:11)
at relative (node:path:1192:5)
at [project_root_dir]/node_modules/@nrwl/js/src/utils/inline.js:171:48
at String.replace (<anonymous>)
at recursiveUpdateImport ([project_root_dir]/node_modules/@nrwl/js/src/utils/inline.js:168:48)
at recursiveUpdateImport ([project_root_dir]/node_modules/@nrwl/js/src/utils/inline.js:177:13)
at updateImports ([project_root_dir]/node_modules/@nrwl/js/src/utils/inline.js:158:5)
at postProcessInlinedDependencies ([project_root_dir]/node_modules/@nrwl/js/src/utils/inline.js:52:5)
at [project_root_dir]/node_modules/@nrwl/js/src/executors/tsc/tsc.impl.js:87:57 {
code: 'ERR_INVALID_ARG_TYPE'
}
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 35 (6 by maintainers)
True
Again, this is not stale. The problem still remains with no official solution for it.
This issue has been automatically marked as stale because it hasn’t had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
@nartc, there is any test I can make to help solving this issue?
As I mentioned before, I don’t have spare time to learn about nx’s codebase, but I want to collaborate with the project.
If, by any chance, someone need an immediate workaround, it is nasty, but adding the following line on the mentioned file works for this version…
node_modules/@nrwl/js/src/utils/inline.js:170
I’m not quite sure if this have side effects, so, I would recommend against doing it on production environments…
This issue has been automatically marked as stale because it hasn’t had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
Yet not stale
@SkyaTura Okay so I found the issue that I was facing. All of my non publishable libraries were buildable (I made them buildable because of the eslint rule).
This caused
to be false. If
shouldInlineis false, it does not set theinlinedDepsDestOutputRecordthus this always being empty. This might be the cause of your problem.After I removed all the builds for the non publishable libraries. I faced a new issue:
Error: ENOENT: no such file or directory, lstat '/Users/itrulia/Documents/wepublish/dist/libs/website/libs/website-api'. This error happens because of this line:movePackage(depOutputPath, destDepOutputPath);When I console.log the variables, I got:
/Users/itrulia/Documents/wepublish/dist/libs/website libs/website-apiwas in the output twice, the 2nd time this is logged, the build fails.If I console.log
Object.values(inlineGraph.dependencies), I am getting this:This is the cause.
re https://github.com/nrwl/nx/issues/16125
Also, I remember to see some tweaks somewhere to helps IDEs (such as VSCode and Volar Vue plugins) to correctly identify types and explicit auto-imports from external libraries.
I’ll try to create a fresh reproduction with that specific settings asap and link here.
Hmm 🤔
That clarifies a lot, one of my packages is a Nuxt@3 application, who basically works by doing some witchcraft on it’s own tsconfig in order to generate auto-imports, although the error itself is being thrown on a dependency library that have nothing special at all.
I don’t remember to deep import nothing from them, however, with that being said, maybe I can try to do some debugging to check if Nuxt isn’t trying to optimize something on build to save bundle size by deep importing files directly.