我的项目有两个文件夹
客户端和服务器都运行,但有时当我访问任何页面时在客户端上运行,因此在终端上以下错误显示了如何修复这些错误
wait - compiling...
warn -
../server/node_modules/mongodb/lib/core/auth/mongodb_aws.js
Module not found: Can't resolve 'aws4' in 'C:\Users\MyName\Desktop\Project\server\node_modules\mongodb\lib\core\auth'
../server/node_modules/mongodb/lib/operations/connect.js
Module not found: Can't resolve 'mongodb-client-encryption' in 'C:\Users\MyName\Desktop\Project\server\node_modules\mongodb\lib\operations'
../server/node_modules/mongoose/lib/index.js
Critical dependency: the request of a dependency is an expression
../server/node_modules/require_optional/index.js
Critical dependency: the request of a dependency is an expression
../server/node_modules/require_optional/index.js
Critical dependency: the request of a dependency is an expression
../server/node_modules/require_optional/index.js
Critical dependency: the request of a dependency is an expression
Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用 TypeScript。如果我尝试使用 commonJS 导入包
\nconst { v4: uuidv4 } = require(\'uuid\');\nRun Code Online (Sandbox Code Playgroud)\n然后我在编译期间不会收到任何错误,但是当我将其转换为 ES6 模块时,例如
\nimport { v4 as uuidv4 } from \'uuid\'; \nRun Code Online (Sandbox Code Playgroud)\n我收到如下编译错误:
\n\n\n找不到模块“uuid”的声明文件。\'C:/Users/project/dependencies/nodejs/node_modules/uuid/dist/index.js\' 隐式具有 \'any\' 类型。尝试\'npm i --save-dev @types/uuid\'(如果存在)或添加包含\'声明模块\'uuid\'的新声明(.d.ts)文件;
\n
我已经安装了@types/uuid。
\n我确实遇到了需要类型定义(@types/*)的包的问题
\n如果项目结构类似于下面的示例:
\nconst { v4: uuidv4 } = require(\'uuid\');\nRun Code Online (Sandbox Code Playgroud)\n要重新生成此问题,请运行下面提到的命令:
\nimport { v4 as uuidv4 } from \'uuid\'; \nRun Code Online (Sandbox Code Playgroud)\n将以下 json 添加到 tsconfig.json 文件:
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependencies\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 nodejs\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x82\xc2\xa0 \xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 node_modules\n\xe2\x94\x82\xc2\xa0 …Run Code Online (Sandbox Code Playgroud)