According to various statements in the PKG docs and support forums, the compilation is supposed to work without PKG config in package.json
I am getting the following warnings - resulting in a failure.
Warning Cannot resolve 'path.join(__dirname, '/services/ddos.js')' /NodeJS/Projects/censored/src/current-app.js Dynamic require may fail at run time, because the requested file is unknown at compilation time and not included into executable. Use a string literal as an argument for 'require', or leave it as is and specify the resolved file name in 'scripts' option.
Warning Cannot resolve 'path.join(__dirname, '/services/db.js')' /NodeJS/Projects/censored/src/current-app.js Dynamic require may fail at run time, because the requested file is unknown at compilation time and not included into executable. Use a string literal as an argument for 'require', or leave it as is and specify the resolved file name in 'scripts' option.
Warning Cannot resolve 'path.join(__dirname, '/routes/lpr-routes.js')' /NodeJS/Projects/censored/src/current-app.js Dynamic require may fail at run time, because the requested file is unknown at compilation time and not included into executable. Use a string literal as an argument for 'require', or leave it as is and specify the resolved file name in 'scripts' option.
Warning Cannot resolve 'path.join(__dirname, '/routes/web-user-routes')' /NodeJS/Projects/censored/src/current-app.js Dynamic require may fail at run time, because the requested file is unknown at compilation time and not included into executable. Use a string literal as an argument for 'require', or leave it as is and specify the resolved file name in 'scripts' option.
Warning Cannot resolve 'path.join(__dirname, '/routes/ipmessages-out-routes')' /NodeJS/Projects/censored/src/current-app.js Dynamic require may fail at run time, because the requested file is unknown at compilation time and not included into executable. Use a string literal as an argument for 'require', or leave it as is and specify the resolved file name in 'scripts' option.
I have tried the various common path syntaxes, as in joining comma separated directories. The current format is because of the PKG docs stating:
Pay attention that path.join must have two arguments and the last one must be a string literal.
I have also tried template literals and process.cwd()variations - all that worked in Node development, but resulted in the same warning / failure.
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.set('view engine', 'ejs')
const path = require('node:path')
app.set('views', path.join(__dirname, '/views'))
app.use(express.static(path.join(__dirname, '/public')))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}))
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(500).send('Sorry - something broke...')
})
const ddos = require(path.join(__dirname, '/services/ddos.js'));
console.log(path.join(__dirname, '/services/ddos.js'));
const crypto = require('crypto');
const http = require('http');
const dotenv = require('dotenv');
dotenv.config()
let { initDbTables, singledbentry, refresh, refreshTwo, ttupdate, mqttDashBoardGauges } = require(path.join(__dirname, '/services/db.js'))
let mysql = require('mysql2');
initDbTables();
const lprRoutes = require(path.join(__dirname, '/routes/lpr-routes.js'));
const webUserRoutes = require(path.join(__dirname, '/routes/web-user-routes'));
const ipMessagesOut = require(path.join(__dirname, '/routes/ipmessages-out-routes'));
app.use('/', lprRoutes);
app.use('/', webUserRoutes);
app.use('/', ipMessagesOut);
How can I get PKG to resolve the paths without listing every asset and script seperately in the package.json config - as that was my precise reason to develop using absolute paths in the first place.
Any help would be much appreciated.