app-module-path-node
app-module-path-node copied to clipboard
not working with module package
Hi
in my package.json I have "type": "module"
{
"type": "module",
"main": "./server/main.js",
"scripts": {
"hello": "echo \"Hello\" && exit 1",
"debug": "ndb main.js",
"dev": "nodemon main.js",
"start": "node main.js",
"dev-docker": "nodemon --legacy-watch main.js"
}
}
jsconfig.json
{
"compilerOptions": {
"baseUrl": "server", /*./src This is where all your code is*/
},
"include": ["server"]
}
In main.js
import { addPath } from 'app-module-path';
addPath(process.cwd())
trying to import like
import { authenticate, developer } from '/server/middlewares/all.js'
but getting error
ode:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/server/middlewares/all.js' imported from /app/server/routes/hello.js
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:321:11)
at moduleResolve (node:internal/modules/esm/resolve:756:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:867:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
environment node 16 docker