Hi everyone, I have an issue with what seems to be...
# help
p
Hi everyone, I have an issue with what seems to be a runtime determined require() in mongodb’s node package… In the MongoDB node source, this code executes
let saslprep;
try {
saslprep = require('saslprep');
} catch (e) {
// don't do anything;
}
and later…
if (cryptoMethod === 'sha256' && saslprep == null) {
emitWarningOnce('Warning: no saslprep library specified. Passwords will not be sanitized');
}
This causes my error monitoring to go haywire because it seems that
saslprep
is null due to some kind of issue with runtime imports of packages. Most Stack Overflow just says to install
saslprep
but that hasn’t solved the problem. Is there a way to explicitly define external dependencies like I would in a webpack config? Or any ideas how to solve this problem? Link for reference: https://stackoverflow.com/questions/53266471/saslprep-warning-when-using-mongoclient-connect/57234317#57234317
f
Hey @Pranav Tadikonda , I think the
nodeModules
in Function’s bundle property is what you are looking for.
In this case:
nodeModules: ["saslprep"]
Let me know if it works for you
p
Awesome I’m trying now. Will this work for Api construct as well?
@Frank
f
Yup, it should work, something like this;
Copy code
new Api(this, "Api", {
  defaultFunctionProps: {
    bundle: {
      nodeModules: ["saslprep"],
    },
  },
  routes: {
    "GET /notes": "src/list.main",
    "POST /notes": "src/create.main",
  },
});