How to handle require(<local dir>)
Hello (again),
So some node_modules have requires like so:
var something = require(__dirname + '/something.js');
And, when deployed, will throw an error like: "Cannot find module '<my local computer dir name>/node_modules/.../something.js'"
I fixed this by modifying the actual node module(s) and replace those imports with:
var something = require('./something.js');
Is there a better way to handle this?
On a related note, for future reference, the pg package has a require('pg-native') that throws Cannot find module 'pg-native' from '[...]/node_modules/pg/lib/native' during deploy. That can be solved with the ignore configuration for babel.
Thanks!
Thanks for this, @thenikso!
Could you please name a npm module which does require(__dirname + '/something.js')?
I have this:
-
node_modules/pgpass/lib/index.js -
node_modules/pg-types/lib/textParsers.js
(got them by npm installing pg-promise, same thing with pg-bricks)
I had this problem with ajv module only on deploy. So I am back with serverless-optimizer-plugin that runs smoothly.