In GraphQLUpload.mjs, 'SyntaxError: Cannot use import statement outside a module'

28 views Asked by At

I use java-script. This mjs file is occured error. I thought that files using the mjs extension would not get this error because they use ESM. So, I don't know this error's solution.

I want that use 'graphql-upload' for file upload, then I import graphql-upload/GraphQLUpload.mjs.

but this error is occured.

this is my import sentence. this file-name is 'editProfile.resolvers.js'

const GraphQLUpload = require('graphql-upload/GraphQLUpload.mjs');

this is error message in terminal. this error occurs

import { GraphQLError, GraphQLScalarType } from"graphql";
^^^^^^

SyntaxError: Cannot use import statement outside a module

this is my 'package.json's depandencies'

"dependencies": {
    "@apollo/client": "^3.9.0",
    "@graphql-tools/load-files": "^7.0.0",
    "@graphql-tools/merge": "^9.0.1",
    "@graphql-tools/schema": "^10.0.2",
    "@prisma/client": "^5.8.1",
    "apollo-server": "^3.13.0",
    "apollo-server-core": "^3.13.0",
    "apollo-server-express": "^3.13.0",
    "apollo-upload-client": "^18.0.1",
    "bcrypt": "^5.1.1",
    "dotenv": "^16.3.2",
    "express": "^4.18.2",
    "graphql": "^16.8.1",
    "graphql-tools": "^9.0.0",
    "graphql-upload": "^16.0.2",
    "jsonwebtoken": "^9.0.2",
    "morgan": "^1.10.0"
  },
  "devDependencies": {
    "@babel/core": "^7.23.7",
    "@babel/node": "^7.22.19",
    "@babel/preset-env": "^7.23.8",
    "nodemon": "^3.0.3",
    "prisma": "^5.8.1"
  },

and I use Node.js 20.10.0

I change import -> const / require sentence. I write 'type:"module" in 'package.json'. then Many error other side.

0

There are 0 answers