random icon indicating copy to clipboard operation
random copied to clipboard

Cannot import successfully

Open mrkresnofatih opened this issue 3 years ago • 1 comments

Cannot import successfully. How do I solve this?

I'm using it like so.

import random from 'random'

//...

const get = () => {
    const num = random.uniformInt(0, 100)();
    return num;
}

but it shows me this:

ERROR in ./node_modules/random/dist/esm/index.esm.js 1:0-30
Module not found: Error: Can't resolve './random' in 'myprojects\project\node_modules\random\dist\esm'
Did you mean 'random.js'?
BREAKING CHANGE: The request './random' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

I tried these but didnt work:

import random from 'random.js'
import random from 'random.ejs'
import random from 'random.esm.js'
import random from 'random.mjs'

mrkresnofatih avatar Jun 21 '22 23:06 mrkresnofatih

Hi @mrkresnofatih! This is a known issue (see #35). The configuration for the package entrypoints are sub-optimal. There are several PR's open with fixes. I anticipate a patch will be released soon.

agmoss avatar Jun 22 '22 03:06 agmoss

Please solve this as soon as possible..

neerajPortalwiz avatar Oct 28 '22 07:10 neerajPortalwiz

Hi @transitive-bullshit can we get the fix for this issue merged?

agmoss avatar Oct 28 '22 15:10 agmoss

Please upgrade to v4 which now exports an ESM module only. Sorry for the issues on previous versions.

transitive-bullshit avatar Nov 08 '22 07:11 transitive-bullshit