【问题标题】:Wildcard imports not working in node14 with es2020通配符导入在 es2020 的 node14 中不起作用
【发布时间】:2021-05-17 04:16:38
【问题描述】:

我正在开发一个快速应用程序,但在导入通配符时遇到问题,例如 import * as E from 'fp-ts/Either';

错误信息:

Error \[ERR\_MODULE\_NOT\_FOUND\]: Cannot find module '/home/adam/code/rbsports/server/node\_modules/fp-ts/Either' imported from /home/adam/code/rbsports/server/dist/controllers/bracket.js

Did you mean to import fp-ts/lib/Either.js?

针对 es2020 的 node 14 应用是否不支持通配符导入?

我的 tsconfig.json

{
  "compilerOptions": {
    "module": "es2020",
    "target": "es2020",
    "lib": ["es2020"],
    "baseUrl": "src",
    "esModuleInterop": true,
    "outDir": "dist",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true
  }
}

我在 package.json 文件夹中使用 node --experimental-specifier-resolution=node . 运行应用程序

package.json 的相关部分

{
  ...
  "type": "module",
  "main": "dist/app.js"
  ...
}

关注this stack overflow post和this github repo

【问题讨论】:

    标签: node.js typescript


    【解决方案1】:

    这可能与您的导入方式有关。我认为Either 存在于fp-ts/lib/Either 中,而您正在从fp-ts/Either 导入

    编辑:您发布的错误消息也说明了这一点,我刚刚注意到

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多