You need to add.js extension index.js:
import { SampleExport } from "../path/file.js"
In my opinion, it is better to use.env files together with some npm package or even a json file.
Nodemon is developer dependency you need to do these commands:
npm uninstall --save nodemon
npm install --save-dev nodemon
Instead of using export itself you should use module.exports = someFuncName
in your env.js
file. export not working and js can not require your function or something...
The issue is a missing file extension. The import needs to look like this:
import { sampleExport } from "../config/env.js";
// ^^^
import
doesn't use the same algorithm that require
used. Instead, it works according to the ECMAScript Modules specification, which requires a definite extension.
This is also explained in the node.js docs for ECMAScript modules :
A file extension must be provided when using the
import
keyword to resolve relative or absolute specifiers. Directory indexes (eg'./startup/index.js'
) must also be fully specified.This behavior matches how
import
behaves in browser environments, assuming a typically configured server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.