错误:在生产中启动 ApolloServer for Express 时找不到模块/ApolloServer/protobufjs/minimal
Posted
技术标签:
【中文标题】错误:在生产中启动 ApolloServer for Express 时找不到模块/ApolloServer/protobufjs/minimal【英文标题】:Error: Cannot find module/ApolloServer/protobufjs/minimal when starting ApolloServer for Express in production 【发布时间】:2021-01-01 00:22:22 【问题描述】:我正在使用 TypeScript 创建一个 ApolloExpressServer。代码在开发模式下运行时运行良好
ts-node -r tsconfig-paths/register ./src --env=development
但是在我使用tsc --build tsconfig.prod.json
构建项目后,它构建成功,但是当我尝试使用node -r module-alias/register ./dist
启动服务器时失败
输出错误
Error: Cannot find module '/dist/ApolloServer/protobufjs/minimal'
Require stack:
- /node_modules/apollo-engine-reporting-protobuf/dist/protobuf.js
- /node_modules/apollo-engine-reporting-protobuf/dist/index.js
- /node_modules/apollo-engine-reporting/dist/agent.js
- /node_modules/apollo-server-core/dist/ApolloServer.js
- /node_modules/apollo-server-core/dist/index.js
- /node_modules/apollo-server-express/dist/index.js
我正在使用
"apollo-server-express": "^2.17.0"
"typescript": "^3.9.3"
复制仓库的链接 https://github.com/Oluwatemilorun/typescript-server
【问题讨论】:
【参考方案1】:我发现了问题。由于我的 package.json 中的 moduleAlias,它正在发生。 我创建了一个模块别名,例如
"name": "apollo-express-server",
"version": "0.0.0",
"_moduleAliases":
"@middlewares": "dist/middlewares",
"@validators": "dist/validators",
"@models": "dist/models",
"@shared": "dist/shared",
"@config": "dist/config",
"@server": "dist/Server",
"@apollo": "dist/ApolloServer"
,
删除“@apollo”行:“dist/ApolloServer”解决了这个问题。 显然它覆盖了 /node_modules/@apollo/* 并将其指向 dist/ApolloServer
【讨论】:
以上是关于错误:在生产中启动 ApolloServer for Express 时找不到模块/ApolloServer/protobufjs/minimal的主要内容,如果未能解决你的问题,请参考以下文章
Dotnet 5 Kubernetes TLS 在生产中失败