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

fix: replace import.meta.resolve with require.resolve for Node 18+ compatibility #9786

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

irmowan
Copy link

@irmowan irmowan commented Feb 6, 2025

Under Node 18+, the tsp-client convert tool met this issue:

TypeError: (intermediate value).resolve is not a function
    at getPathToDependency (file:///C:/nvm/v18.15.0/node_modules/@azure-tools/typespec-client-generator-cli/dist/utils.js:55:50)
    at convertCommand (file:///C:/nvm/v18.15.0/node_modules/@azure-tools/typespec-client-generator-cli/dist/commands.js:321:32)
    at async Object.handler (file:///C:/nvm/v18.15.0/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:170:5)

In Node.js, there is no built-in import.meta.resolve() API. That function is a browser feature and isn’t implemented in Node 18 (nor in later versions at time of writing). If you need to resolve a module path in an ES module, the simplest solution is to use createRequire from the module package.

After I patched this commit in my local module, the issue is fixed.

@irmowan irmowan changed the title fix: replace import.meta.resolve with require.resolve for Node 18compatibility fix: replace import.meta.resolve with require.resolve for Node 18+ compatibility Feb 6, 2025
Remove useless import
Copy link
Member

@catalinaperalta catalinaperalta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reaching out about this. Unfortunately, we require node 18.19+ to use tsp-client since we use several components that are not compatible with lower node versions. I wouldnt want to add this simply to try to support a lower node version for one command in the tool.

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

Successfully merging this pull request may close these issues.

2 participants