Skip to content

SyntaxError: Cannot use import statement outside a module #12

Description

@profiluefter

Hi,
there are already a few issues due to build problems however the error I'm getting is not among them.

After adding an import of the package to my next.js project (using TypeScript) I get the following error:

error - ...\node_modules\json-diff-kit\dist\index.js:2453
import * as React from "react";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at json-diff-kit (...\.next\server\pages\audit.js:339:18)
    at __webpack_require__ (...\.next\server\webpack-runtime.js:33:42) {
  page: '/audit'
}

The mentioned (compiled) file does indeed contain the import:
grafik

This is the only import in this compiled file so I guess it is a build error and the other imports got adjusted properly.

Maybe this import could be adjusted to just import the used function/types/etc and not everything and that might resolve the issue:

import * as React from 'react';

Also just in case this import exists because it was necessary to import React in older versions of React, this is no longer the case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions