[英]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:我有一个位于
project/src/services/translations.js
的translations.ts
文件,它导出以下数组:
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:我正试图将它导入到位于
project/src/scripts/generateStrings.mjs
的generateStrings.mjs
文件中,如下所示:
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.我的 IDE 无法仅在该特定文件中自动导入数组。 I wonder if it is because the file has
.mjs
extension?请问是不是因为文件的后缀是
.mjs
?
mistype, import from translationS
, and file named translation.js
without S
at the end输入错误,从
translationS
导入,文件名为translation.js
,但末尾没有S
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.