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

Importing in node 21 #132

Open
BobFrankston opened this issue Nov 2, 2023 · 10 comments
Open

Importing in node 21 #132

BobFrankston opened this issue Nov 2, 2023 · 10 comments

Comments

@BobFrankston
Copy link

I'm trying to convert to the userland vs the built-in Punycode but node seems to have tightened the rules.

import puny from 'punycode/'

generates an ERR_UNSUPPORTED_DIR_IMPORT error. What is the proper module syntax?

@MikeMcC399
Copy link
Contributor

@BobFrankston

Have you tried the following?

import punycode from 'punycode/punycode.js'

Your full error message may have suggested this.

@BobFrankston
Copy link
Author

BobFrankston commented Nov 3, 2023 via email

@BobFrankston
Copy link
Author

BobFrankston commented Nov 3, 2023 via email

@MikeMcC399
Copy link
Contributor

@BobFrankston

I was able to remote in and tried that case. It now complains about the lack of a declaration file. I have installed @types/punycode but that didn’t solve it.

You may want to consider following the instructions in the README > Installation, using the recommended code line:

const punycode = require('punycode/');

It sounds like you are using TypeScript.

@BobFrankston
Copy link
Author

BobFrankston commented Nov 4, 2023 via email

@MikeMcC399
Copy link
Contributor

@BobFrankston

Well I'm quite out of my depth by now, as I am no TypeScript expert, and this should probably be converted into an enhancement request for built-in TypeScript support, so that you don't have to jump through hoops.

However, I tried to simulate what you're doing and after I added the following file, I didn't get errors from import.

Filename: punycode.d.ts

with the one line

declare module 'punycode/punycode.js';

If that doesn't work, then it would be helpful if you could supply a minimum reproducible example, including

package.json
tsconfig.json

+ your TypeScript file that is using punycode

@BobFrankston
Copy link
Author

BobFrankston commented Nov 4, 2023 via email

@BobFrankston
Copy link
Author

BobFrankston commented Nov 7, 2023 via email

@BobFrankston
Copy link
Author

BobFrankston commented Nov 7, 2023 via email

@hrueger
Copy link

hrueger commented Jan 21, 2024

I just submitted a patch for this to DefinitelyTyped: DefinitelyTyped/DefinitelyTyped#68273 🎉

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

No branches or pull requests

3 participants