我需要在我的 React 客户端和 Express REST API 之间共享一些 TypeScript 类型,以保持代码干净和干燥。\n由于这是一个私有项目,我不会通过 @types 存储库共享这些类型,所以我按照 TypeScript 网站上的指南进行操作,这就是结果......
\nReact 客户端中的一切都运行良好:我已将类型安装为开发依赖项并完美地使用它们。
\n在 Express API 中,我收到此错误,我认为它与我构建包的方式有关。
\n我做错了什么?\n尽管我很无知,但我认为这与模块的加载方式有关,但我无法准确地弄清楚是什么导致了错误。
\n> cross-env NODE_ENV=production node dist/index.js\n\ninternal/modules/cjs/loader.js:834\n throw err;\n ^\n\nError: Cannot find module \'@revodigital/suiteods-types\'\nRun Code Online (Sandbox Code Playgroud)\n如何在 API 代码中导入模块
\n> cross-env NODE_ENV=production node dist/index.js\n\ninternal/modules/cjs/loader.js:834\n throw err;\n ^\n\nError: Cannot find module \'@revodigital/suiteods-types\'\nRun Code Online (Sandbox Code Playgroud)\nsuiteods-types\n |_index.d.ts\n |_package.json\n |_README.md\n |_tsconfig.json\n\nRun Code Online (Sandbox Code Playgroud)\n索引.d.ts
\nimport { AuthEntity, Roles } from \'@revodigital/suiteods-types\';\n\n@Model()\nexport class AuthEntityModel implements AuthEntity {\n /* ... */\n\n role: …Run Code Online (Sandbox Code Playgroud)