mathiasbynens / punycode.js

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891.
https://mths.be/punycode
MIT License
1.59k stars 158 forks source link

Importing in node 21 #132

Open BobFrankston opened 10 months ago

BobFrankston commented 10 months ago

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 commented 10 months ago

@BobFrankston

Have you tried the following?

import punycode from 'punycode/punycode.js'

Your full error message may have suggested this.

BobFrankston commented 10 months ago

I did try it and it used to work. I'm traveling now so won't be able to get you the exact error message till I get back next week. I'm using "NodeNext" for the module settings.

On 2023-11-03 09:18, Mike McCready wrote:

@BobFrankston [1]

Have you tried the following?

import punycode from 'punycode/punycode.js'

Your full error message may have suggested this.

-- Reply to this email directly, view it on GitHub [2], or unsubscribe [3]. You are receiving this because you were mentioned.Message ID: @.***>

Links:

[1] https://github.com/BobFrankston [2] https://github.com/mathiasbynens/punycode.js/issues/132#issuecomment-1792423727 [3] https://github.com/notifications/unsubscribe-auth/ABJ4ONAT5WILPQUEI5KRTLTYCTVMBAVCNFSM6AAAAAA63GYALSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJSGQZDGNZSG4

BobFrankston commented 10 months ago

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.

From: Mike McCready @.> Sent: Friday, November 3, 2023 06:19 To: mathiasbynens/punycode.js @.> Cc: Bob Frankston @.>; Mention @.> Subject: Re: [mathiasbynens/punycode.js] Importing in node 21 (Issue #132)

@BobFrankston https://github.com/BobFrankston

Have you tried the following?

import punycode from 'punycode/punycode.js'

Your full error message may have suggested this.

— Reply to this email directly, view it on GitHub https://github.com/mathiasbynens/punycode.js/issues/132#issuecomment-1792423727 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ4ONAT5WILPQUEI5KRTLTYCTVMBAVCNFSM6AAAAAA63GYALSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJSGQZDGNZSG4 . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ABJ4ONCT5QH2CUK2S3DTGUTYCTVMBA5CNFSM6AAAAAA63GYALSWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTK2Y3S6.gif Message ID: @. @.> >

MikeMcC399 commented 10 months ago

@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 commented 10 months ago

I’m using typescript with modules so must use import. One option is to make a version available with an @ qualified name. I can do that with a clone but would rather use a supported version.

From: Mike McCready @.> Sent: Friday, November 3, 2023 23:36 To: mathiasbynens/punycode.js @.> Cc: Bob Frankston @.>; Mention @.> Subject: Re: [mathiasbynens/punycode.js] Importing in node 21 (Issue #132)

@BobFrankston https://github.com/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 https://github.com/mathiasbynens/punycode.js#installation > Installation, using the recommended code line:

const punycode = require('punycode/');

It sounds like you are using TypeScript.

— Reply to this email directly, view it on GitHub https://github.com/mathiasbynens/punycode.js/issues/132#issuecomment-1793360707 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ4ONHAXHDYJQG7QUYDJ2LYCXO5PAVCNFSM6AAAAAA63GYALSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJTGM3DANZQG4 . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ABJ4OND4ML4E2KJVIUBEUUDYCXO5PA5CNFSM6AAAAAA63GYALSWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTK4SBUG.gif Message ID: @. @.> >

MikeMcC399 commented 10 months ago

@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 commented 10 months ago

Thx I'll give it a tryGet Outlook for Android

BobFrankston commented 10 months ago

I managed to remote in and it worked. Thanks.

Awkward but workable.

From: Mike McCready @.> Sent: Saturday, November 4, 2023 07:31 To: mathiasbynens/punycode.js @.> Cc: Bob Frankston @.>; Mention @.> Subject: Re: [mathiasbynens/punycode.js] Importing in node 21 (Issue #132)

@BobFrankston https://github.com/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

— Reply to this email directly, view it on GitHub https://github.com/mathiasbynens/punycode.js/issues/132#issuecomment-1793460240 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ4ONDSFUZW5BOPOKIJQHLYCZGSTAVCNFSM6AAAAAA63GYALSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJTGQ3DAMRUGA . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ABJ4ONFAFNIVSZ5M7VZNA33YCZGSTA5CNFSM6AAAAAA63GYALSWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTK4YEBA.gif Message ID: @. @.> >

BobFrankston commented 10 months ago

Maybe spoke too soon – still getting runtime error …

From: Bob Frankston @.> Sent: Monday, November 6, 2023 20:40 To: 'mathiasbynens/punycode.js' @.>; 'mathiasbynens/punycode.js' @.> Cc: 'Bob Frankston' @.>; 'Mention' @.***> Subject: RE: [mathiasbynens/punycode.js] Importing in node 21 (Issue #132)

I managed to remote in and it worked. Thanks.

Awkward but workable.

From: Mike McCready @. @.> > Sent: Saturday, November 4, 2023 07:31 To: mathiasbynens/punycode.js @. @.> > Cc: Bob Frankston @. @.> >; Mention @. @.> > Subject: Re: [mathiasbynens/punycode.js] Importing in node 21 (Issue #132)

@BobFrankston https://github.com/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

— Reply to this email directly, view it on GitHub https://github.com/mathiasbynens/punycode.js/issues/132#issuecomment-1793460240 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ4ONDSFUZW5BOPOKIJQHLYCZGSTAVCNFSM6AAAAAA63GYALSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJTGQ3DAMRUGA . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ABJ4ONFAFNIVSZ5M7VZNA33YCZGSTA5CNFSM6AAAAAA63GYALSWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTK4YEBA.gif Message ID: @. @.> >

hrueger commented 7 months ago

I just submitted a patch for this to DefinitelyTyped: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/68273 🎉