我有一个默认的NestJS项目,MikroORM 4,使用WebPack构建。该项目是通过以下方式创建的:
nest new <project>
当我向项目添加一个库时,WebPack被激活了--这是NestJS的默认行为。然后,我将我的项目从4.5迁移到了5.1,现在我在开始时出现了这个错误:
webpack 5.71.0 compiled successfully in 1338 ms
Type-checking in progress...
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './typings' is not defined by "exports" in D:\a\_NEST8_MIKRO5\nest-mikro-test\node_modules\@mikro-orm\core\package.json
at throwExportsNotFound (internal/modules/esm/resolve.js:285:9)
at packageExportsResolve (internal/modules/esm/resolve.js:508:3)
at resolveExports (internal/modules/cjs/loader.js:450:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.@mikro-orm/core/typings (D:\a\_NEST8_MIKRO5\nest-mikro-test\dist\main.js:967:18)
at __webpack_require__ (D:\a\_NEST8_MIKRO5\nest-mikro-test\dist\main.js:1051:42)
No errors found.
WebPack不是手动添加的,而是由NestJS提供的,如果您在ned-cli.json中配置它的话。
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"webpack": true <<<<<<<<<<<<<<< WebPack enabled here
}
}
可以成功地完成项目。此错误出现在启动过程中。这个问题与WebPack有关。如果它被禁用(在ned-cli.json中),那么它可以正常运行。
一个选项是以某种方式定制WebPack构建,但我不知道如何自定义由NestJS配置的WebPack (如果可能的话,可以保留NestJS配置的WebPack)。是否可以将自定义WebPack配置添加到NestJS?
您可以从这里下载该项目:https://github.com/tferi99/nest-mikro-test
发布于 2022-04-13 14:29:31
您不应该对来自MikroORM包的任何内容使用深度导入。如果您需要一些没有导出的符号,可以随意发送一个PR,将其添加到公共出口。
检查您的复制,我发现了这个地方,您从@mikro-orm/core/typings
,而不是仅仅从@mikro-orm/core
导入。这个符号肯定是从包的根导出的EntityData
。
https://github.com/tferi99/nest-mikro-test/blob/main/src/person/model/person.entity.ts#L2
https://stackoverflow.com/questions/71858988
复制相似问题