javascript - the error is Cannot read properties of undefined (reading 'random') while trying to get random name

admin2025-04-16  2

import superheroes from 'superheroes';
console.log(superheroes.default.random());

for this code I got this error

(node:1512) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time

(Use `node --trace-warnings ...` to show where the warning was created)
file:///C:/Users/nikhi/Downloads/2.3+NPM%20(1)/2.3%20NPM/index.js:7
console.log(superheroes.default.random());
                                ^

TypeError: Cannot read properties of undefined (reading 'random')
    at file:///C:/Users/nikhi/Downloads/2.3+NPM%20(1)/2.3%20NPM/index.js:7:33
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:482:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) how to solve this 

In my tutorials they have taught me this

import superheroes from 'superheroes';
console.log(superheroes.default.random());

I expect you to give correct code to get output

转载请注明原文地址:http://www.anycun.com/QandA/1744734544a86868.html