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

Improve documentation about how to import in Typescript+Node<13.11 #210

Closed
peps opened this issue Feb 9, 2020 · 7 comments · Fixed by #474
Closed

Improve documentation about how to import in Typescript+Node<13.11 #210

peps opened this issue Feb 9, 2020 · 7 comments · Fixed by #474

Comments

@peps
Copy link

peps commented Feb 9, 2020

Hi, im trying to use Hashids with Typescript and Node.

import Hashids from 'hashids';

I'm not getting any Typescript errors in the editor, but Im getting this error when the code is compiled.

Using ts-node version 8.5.4, typescript version 3.7.5

Error: No valid exports main found for 'node_modules\hashids' at resolveExportsTarget (internal/modules/cjs/loader.js:625:9) at applyExports (internal/modules/cjs/loader.js:502:14) at resolveExports (internal/modules/cjs/loader.js:551:12) at Function.Module._findPath (internal/modules/cjs/loader.js:657:22) at Function.Module._resolveFilename (internal/modules/cjs/loader.js:960:27) at Function.Module._load (internal/modules/cjs/loader.js:855:27) at Module.require (internal/modules/cjs/loader.js:1033:19) at require (internal/modules/cjs/helpers.js:72:18) at Object.<anonymous> (encodeID.ts:1:1) at Module._compile (internal/modules/cjs/loader.js:1144:30) [ERROR] 18:03:43 Error: No valid exports main found for 'node_modules\hashids'

Thanks!

@oleg-koval
Copy link

@peps have the same issue,

Temporarily fixed with:

declare let require: any;
const Hashids = require('hashids/cjs');

Would be good to have an update on this

@enahomurphy
Copy link

this works for me import hashids from 'hashids/cjs'

@niieani
Copy link
Owner

niieani commented Mar 20, 2020

See README: https://github.com/niieani/hashids.js#use-in-commonjs-environments-most-often-nodejs
You need to require or import a different file depending on the environment, just like @enahomurphy suggested. One exception is if you use Node >=13.11, so it also will work out of the box from the main import in the upcoming Node 14 LTS.

@niieani niieani changed the title import not working in Node v13.6.0 with Typescript Improve documentation about how to import in Typescript+Node<13.11 Mar 20, 2020
@YashdalfTheGray
Copy link
Contributor

I'd like to take this on if no one is working on it!

@niieani
Copy link
Owner

niieani commented Oct 24, 2021

@YashdalfTheGray go for it!

@YashdalfTheGray
Copy link
Contributor

I created #474 to hopefully close this!

@github-actions
Copy link

github-actions bot commented Nov 7, 2021

🎉 This issue has been resolved in version 2.2.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

5 participants