I can’t figure out why this import is failing. I have tried everything I can think of, changed the export and import to every single tutorial I can find online, and every single time it fails. Theoretically this should be very simple….
server.js
import express from 'express'
import sqlite3 from 'sqlite3'
import fetch from 'node-fetch'
import config from './config'
//rest of my code here...
config.js
const config = {
url: "my url string here",
port: 5000,
callbackURL: "another url here"
}
export default config
in my package.json file I do have "type": "module"
in there and all the imports from the node modules work just fine, it just fails on the config import. When I try to run the code above I get…
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '{path}/config' imported from '{path}/server.js
… Did you mean to import ..config.js?
But there is no ../config.js, both server.js and config.js are in the same directory
I figured this should be something easy, I just need to import a module that I am creating, but nothing works, it always tells me if can’t find the module config. I’ve tried changing the name thinking maybe config was reserved. So I changed to settings.js, same thing, Cannot find module settings.
I’ve tried changing the export to numerous ways, stuff like…
config.js
const config = {
url: "my urls",
port: 5000,
callbackURL: "another"
}
export { config }
then changing my import to import { config } from './config'. Same thing. I've tried removing the
./` in front of config, same thing. I’m pretty lost, any help would be really appreciated. Thank you.
Just for extra information here is my actual package.json…
{
"name": "my_test_app",
"version": "1.0.0",
"description": "",
"main": "server.js",
"type": "module",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"node-fetch": "^2.7.0",
"request": "^2.88.2",
"sqlite3": "^5.1.6"
}
}
And I am trying to run it with npm start
in terminal