I try to import javascript-code into my express server to be used, but get the follwing error when starting the express server with
node TestProxy.js
Error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\develop\mytestproject\src\proxy\testcode' imported from C:\develop\mytestproject\src\proxy\TestProxy.js
Did you mean to import ../testcode.js?
←[90m at new NodeError (node:internal/errors:372:5)←[39m
←[90m at finalizeResolution (node:internal/modules/esm/resolve:437:11)←[39m
I have the following setup:
My Server (TestProxy.js) looks like this:
const express = require('express')
const app = express()
import { testMethod } from "./testcode";
app.get('/myrequest', function(req, res){
testMethod
})
app.listen(3002)
My javascript code (testcode.js) looks like this:
export const testMethod = () => {
console.debug('in testMethod!')
}
My Project structure:
under src I have:
My package.json:
{
"name": "myname",
"type": "module",
"version": "1.0.0",
...
...
"devDependencies": {
...
...
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.9.2"
},
"dependencies": {
...
...
"express": "^4.18.1",
...
...
}
}