Skip to content

Importing in node 21 #132

Open
Open

Description

@BobFrankston

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?

Activity

  1. MikeMcC399 commented on Nov 3, 2023

    @MikeMcC399
    Contributor

    @BobFrankston

    Have you tried the following?

    import punycode from 'punycode/punycode.js'

    Your full error message may have suggested this.

  2. BobFrankston commented on Nov 3, 2023

    @BobFrankston
    Author
  3. BobFrankston commented on Nov 3, 2023

    @BobFrankston
    Author
  4. MikeMcC399 commented on Nov 4, 2023

    @MikeMcC399
    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.

  5. BobFrankston commented on Nov 4, 2023

    @BobFrankston
    Author
  6. MikeMcC399 commented on Nov 4, 2023

    @MikeMcC399
    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

  7. BobFrankston commented on Nov 4, 2023

    @BobFrankston
    Author
  8. BobFrankston commented on Nov 7, 2023

    @BobFrankston
    Author
  9. BobFrankston commented on Nov 7, 2023

    @BobFrankston
    Author
  10. hrueger commented on Jan 21, 2024

    @hrueger

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions