简体   繁体   中英

Why am I unable to import an exported array in my script? Getting [ERR_MODULE_NOT_FOUND]: Cannot find module error

I have a translations.ts file located at project/src/services/translations.js that exports the following array:

export const supportedLocales = ['en', 'es'];

And I am attempting to import it in generateStrings.mjs file which is located at project/src/scripts/generateStrings.mjs like this:

import { supportedLocales } from '../services/translations';

But I get an error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/User/Desktop/Projects/mobile/src/services/translations' imported from /Users/User/Desktop/Projects/mobile/src/scripts/generateStrings.mjs

My IDE couldn't automatically import the array either only in that specific file. I wonder if it is because the file has .mjs extension?

mistype, import from translationS , and file named translation.js without S at the end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM