0

I don't see where is my error in this code, can you help me? import app from "../app"; ^^^^^^

I had add this "type": "module" in my package.json but my server stop to run.

const request = require("supertest");
import app from "../app";



describe("Test the root path", () => {
  test("It should response the GET method", () => {
    return request(app).get('/').then((res) => {
        expect(res.statusCode).toBe(200);
      });
  });
});

1
  • I think you can't use require with "type": "module", Node returns the following error: ReferenceError: require is not defined in ES module scope, you can use import instead, also you are missing the .js extension Commented Jan 5, 2023 at 21:59

1 Answer 1

2

you can't use ES6 module with "type": module setting together with CommonJs which use require, so pick one you prefer :

CommonJs :

const request = require("supertest");
const app = require("../app.js");

ES module:

import request from 'supertest'; // supertest should now support ES6.
import app from "../app.js";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.