Require isn't defined

I’m trying to include a module from node.js in a .js file, and I can’t do that with import because it throws an error. I’m trying to do that with require, but Glitch keeps giving me a require is not defined error for some reason.
I tried changing the file extension to .cjs, but Glitch gives me an error about mime types or whatever.
I don’t know what to do here.

Also, when I look at the Glitch starter for node.js, Glitch seems to think nothing is wrong, even when the file extension is .js. So why am I getting this error and not the Glitch starter, even though we have the exact same file terminations?

is your project a static site? because static sites can’t import modules from npm.

I don’t know. The project is a collab between me and someone else, so I can’t check if it’s static or not.

A static site only includes HTML, CSS, and/or JS files. If there’s a package.json, it no longer is.

Also…I think this might be helpful: JavaScript modules - JavaScript | MDN

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