This error message typically occurs in JavaScript or TypeScript when you try to use the IMPORT statement in a file that is not recognized as a module.

To resolve this issue, you need to make sure that the file where you are using the IMPORT statement is treated as a module.

There are two modules which we are following when we are developing project structure So below I am going to explain on both module How you can add support of import statement.

1. Use ECMAScript Modules (ESM):

If you are using Node.js, make sure your file has the .mjs extension or set “type”: “module” in your package.json file. This enables ECMAScript Modules, allowing you to use import and export statem

Example:

// package.json
{
  		"type": "module"
}

Create file with .mjs extension.
// yourfile.mjs
import { file_path } from './file_path';

 

2. CommonJS Modules:

If you don’t want to use ECMAScript Modules, you can use require syntax instead of import. This is typical in CommonJS modules.

Example:

// yourfile.js
const file = require('./file_path');

Support On Demand!

Node