0

I'm working on NodeJs project

This is not working

import Env from "./utils/Env";

Error [ERR_MODULE_NOT_FOUND]: Cannot find module ...\Env

This is my Env.js code

export default class Env {
  static isLocal() {
    return !(process.env.NODE_ENV === 'production');
  }
  static isProd() {
    if (process.env.NODE_ENV === 'production' && process.env.GCLOUD_PROJECT === 'extendedbuilder') {
        return true;
    }
    return false;
  }
}

But if I add .js, then works

import Env from "./utils/Env.js";

Is there any way for ignoring the ".js" when I'm importing the module?

Thank you

Piece
  • 708
  • 13
  • 15
  • ES6 `import` syntax requires the file extension, per the Javascript specification. This is different than how `require()` works in nodejs for CommonJS modules. – jfriend00 Nov 04 '21 at 23:57

1 Answers1

0

This thread has a example that can solve your problem - https://stackoverflow.com/a/34967457/17289563

See export syntax on MDN - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

  • It's unclear what this has to do with anything in this question. The OP is asking about file extensions. That is not mentioned in your answer or in the referenced other post. I think perhaps you're confused about what is being asked here. – jfriend00 Nov 04 '21 at 23:58