I am trying to import a js file at runtime:
const migrationsDir = path.resolve(__dirname, '../migrations/tenanted');
import(path.join(migrationsDir, '1681831306977-initial-schema.js'))
.then(() => {
console.log('done');
})
.catch((e) => console.error(e));
it doesn’t work if I compile a project with webpack:
Error: Cannot find module 'path1681831306977-initial-schema.js'
at ...some_pathlambda.js:157949:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'MODULE_NOT_FOUND'
}
Webpack compiled the code to be:
const migrationsDir = path__WEBPACK_IMPORTED_MODULE_1___default().resolve(__dirname, '../migrations/tenanted');
__webpack_require__("./src/database/migrations lazy recursive")(path__WEBPACK_IMPORTED_MODULE_1___default().join(migrationsDir, '1681831306977-initial-schema.js')).then(()=>{
console.log('done');
}).catch((e)=>console.error(e));
the problem, is that webpack_require(“./src/database/migrations lazy recursive”) returns webpackEmptyAsyncContext
.
Anything I forgot to config?