I'm not a js expert, and my question might be out of scope, but I've been struggling for a while and tried so many solutions I have found here and here and more, but no success!!
this is the app hierarchy:
app
|
public
|
static
|
node-modules
|
connection
server.js
package.json
this is package.json
{
"name": "appp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "me",
"license": "MIT",
"dependencies": {
"connection": "file:../dbconnection",
"express": "^4.17.1",
"pg": "^8.7.1"
},
"devDependencies": {
"@types/node": "^16.6.1"
}
}
I assume the problem comes from "connection": "file:../dbconnection",
since I think it shouldn't have file: in front of it. I have installed that via npm install --save dbconnection
.
dbconnection module index.js:
import pkg from 'pg';
const {Client} = pkg;
export default client = new Client({
host:"localhost",
port: 5432,
user: 'sha13',
password: "ShieldTec2021",
database: "shieldtec"
});
I also have tried to export default class from the module and export functions from that too, but didn't work.
the error I get every time is the same:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
in another .js file I try
import { client } from '../../../node_modules/connection /index.js';
what cause the problem?