Unexpected string in dotenv import

I apologize if this error is extremely easily fixed. I am just getting started with Node.js Discord bot development with slash commands, and I am not having any luck finding answers elsewhere online.

I am programming a bot based on this example Discord app. The project runs perfectly well on my machine. When I run it on Glitch, however, I see the following error:

import "dotenv/config";
SyntaxError: Unexpected string
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Here are the first few lines of app.js:

import "dotenv/config";
import express from "express";

What can I do to permit Glitch to recognize this import statement?

Hi @theSignSaysDie - I think this is an easy fix, but not so easy to find, so don’t feel self-conscious there! If you’re importing that repo into a Glitch app, it’s going to use the default Node version of 10. Since it’s a Discord app and using import statements, you’ll want to use a more modern version of Node. You can see how to set this in this doc here, I recommend Node 16 Can I change the version of node.js my project uses? - Glitch Support


That did the trick! Thank you so much!


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.