#Argon2 import not working
32 messages · Page 1 of 1 (latest)
Is this while running, while installing argon, while doing something else?
I have a monorepo. It's when building with yarn build
Ah, this would most likely be because you're trying to bundle everyhting (node_modules included) into a single file. We usually don't recommend that for Node servers
Do you have a customized webpack.config.js file?
module.exports = (options, webpack) => {
const lazyImports = [
'@nestjs/microservices/microservices-module',
'@nestjs/websockets/socket-module',
'@nestjs/platform-express'
]
return {
...options,
externals: [],
output: {
...options.output,
libraryTarget: 'commonjs2'
},
plugins: [
...options.plugins,
new webpack.IgnorePlugin({
checkResource(resource) {
if (lazyImports.includes(resource)) {
try {
require.resolve(resource)
} catch (err) {
return true
}
}
return false
}
})
]
}
}
Ah, yeah, externals: []. I would not recommend that
My tsconfig.build.json is ignoring it
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
That's just the Typescript compiler ignoring the file. Webpack will still try to bundle it
Ah
Webpack isn't really my strong point, so do you recommend anything in particular?
I just took this config out the docs for a quick fix
Remove the externals: [] and I think everything should work because Nest's default adds in the fact that node_modules should be external to the bundle (meaning you still need to install them)
Hmm, OK so now my serverless handler is not being recognised as a Function
This happened earlier with a fix that I tried. What I did was add this in my config:
exclude:path.resolve(__dirname, "node_modules")
And it gave me the new error, which this solution now does too
No clue about serverless to be honest. Never dabbled wit hthat
But it's related to the change I just made. If I remove argon2 imports and reverse the changes, it runs fine
I'm thinking it might even be easier to uninstall argon2 and try bycrypt, this is causing too much troube
If you go with bcrypt use bcryptjs. Otherwise you'll get the same issue
bcrypt and argon both normally use c++ bindings for the extra speed. bcryptjs is a pure js implementation of bcrypt. It's about 30% slower, but doesn't require c++ bindings
That'll be fine then, I will try a bit to solve this though
I'm using the aws-lambda package. You reckon I need to add that in the webpack config somewhere? maybe it's being ignored now
maybe in the lazyimports?
I import the handler as such import { Callback, Context, Handler } from 'aws-lambda'
What's the specific error you're getting?
✖ offline: handler 'handler' in /home/Documents/Code/app/dist/apps/api/main is not a function
✖ Error: offline: handler 'handler' in /home/Documents/Code/app/dist/apps/api/main is not a function
When I make a request to the endpoint.
I posted in the serverless group too as someone might know but I suspect it's something to do with webpack
That would seem like handler is being viewed as undefined. Can you show how you define it?
Sure, this is my main file
import { configure as serverlessExpress } from '@vendia/serverless-express'
import { Callback, Context, Handler } from 'aws-lambda'
import { NestFactory } from '@nestjs/core'
import compression from 'compression'
import { IndicatorsApiModule } from './indicators-api.module'
let server: Handler
async function bootstrap(): Promise<Handler> {
const app = await NestFactory.create(IndicatorsApiModule)
await app.init()
app.enableCors()
app.use(compression())
const expressApp = app.getHttpAdapter().getInstance()
return serverlessExpress({ app: expressApp })
}
export const handler: Handler = async (event: any, context: Context, callback: Callback) => {
server = server ?? (await bootstrap())
return server(event, context, callback)
}
I can see the file main in dist/api/main. The transpiled code has the Handler inside it. I think it's having trouble now importing from the aws-lambda lib
very strange for me to understand how after removing excludes: []