motdotla / dotenv

Loads environment variables from .env for nodejs projects.
https://www.dotenvx.com
BSD 2-Clause "Simplified" License
19.01k stars 853 forks source link

Attempting to import into ES6 yields error #821

Closed jauntyjocularjay closed 5 months ago

jauntyjocularjay commented 5 months ago

Expected behavior:

Import dotenv using the instructions in the readme.md

Actual Behavior:

import 'dotenv/config'

Yields an error in Chrome

Uncaught TypeError: Failed to resolve module specifier "dotenv/config". Relative references must start with either "/", "./", or "../".

notes:

Error files: I have preserved the error in a branch of my project. IDE: VSCode Browser: Chrome Version 122.0.6261.129 (Official Build) (64-bit) OS: Windows 10

motdotla commented 5 months ago

does this format work for you:

import { config } from "dotenv";
config();
motdotla commented 5 months ago

see this thread: https://github.com/motdotla/dotenv/issues/89#issuecomment-1962908568

jauntyjocularjay commented 5 months ago

Interesting, I am not using nextjs to my knowledge, unless Phaser uses that under the hood.

jauntyjocularjay commented 5 months ago

does this format work for you:

import { config } from "dotenv";
config();

Same result.

Console:

Uncaught TypeError: Failed to resolve module specifier "dotenv". Relative references must start with either "/", "./", or "../".
jauntyjocularjay commented 5 months ago

It doesn't look like Phaser uses NextJS under the hood. I don't have a next.config.js file to modify.

jonjieviduya commented 5 months ago

I still get "process not defined"