目标
我正在用TypeGraphql做一个项目,我想实现用户配置文件图片。
问题
当我尝试导入:
import { GraphQLUpload, FileUpload } from "graphql-upload";
docker容器日志返回:
src/resolvers/user.resolver.ts(25,43): error TS2307: Cannot find module 'graphql-upload' or its corresponding type declarations. `
Tsconfig
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
"skipLibCheck": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"baseUrl": "."
},
"exclude": ["node_modules"],
"include": ["./src/**/*.ts"]
}
我尝试了什么
我试着安装旧版本,但没有用。
如果你能帮我,我会很高兴的。
谢谢。
最新的graphql上传版本16.0.0不适用于node 16 typescript。然而,降级到之前的15.0.2版本与以下替换版本一起工作,
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
你能用这个代替吗
import { GraphQLUpload } from "graphql-upload/GraphQLUpload";
import { Upload } from "graphql-upload/Upload";
这样导入:
import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.js"
并在tsconfig.json文件中添加此行:
"compilerOptions": {
"allowJs": true,
"strict": false
}
为了允许您导入javascript模块,它对我有效
学习ESM和CJS。
我添加了
"module": "ESNext",
"moduleResolution": "node",
到我的tsconfig.json.
和
import graphqlUploadExpress from 'graphql-upload/GraphQLUpload.mjs';
到我的服务
和
"type": "module",
到我的包.json