close

[Solved] Node –experimental-modules – Error: Cannot find module

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Node –experimental-modules – Error: Cannot find module in nodejs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How To Solve Node –experimental-modules – Error: Cannot find module Error ?

  1. How To Solve Node –experimental-modules – Error: Cannot find module Error?

    To Solve Node –experimental-modules – Error: Cannot find module Error use type=”module” on package.json, experimental modules and specify extensions with specidier-resolution like this: node –experimental-modules –es-module-specifier-resolution=node src/index

  2. Node –experimental-modules – Error: Cannot find module

    To Solve Node –experimental-modules – Error: Cannot find module Error use type=”module” on package.json, experimental modules and specify extensions with specidier-resolution like this: node –experimental-modules –es-module-specifier-resolution=node src/index

Solution 1

It turns out in experimental mode you need to define the full path with extension. So I am trying to import index.js thinking it will know.

To fix it:

import express from 'express'
import next from 'next'
import api from './src/server/api/index.js'

Solution 2

on node 12 you have 2 options:

  1. use type=”module” on package.json, experimental modules and specify extensions with specidier-resolution like this: node --experimental-modules --es-module-specifier-resolution=node src/index
  2. or not using specifier-resolution. Keep in mind you’ll have to specify the extension of your files every where.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment