-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Noncritical errors when bundling with webpack #212
Comments
The errors disappear when commenting out the following lines in the main function grant ({handler, ...rest}) {
if (handler === 'express') {
var version = 4
}
// else if (handler === 'koa') {
// var version =
// parseInt(require('koa/package.json').version.split('.')[0]) >= 2 ? 2 : 1
// }
// else if (handler === 'hapi') {
// try {
// var pkg = require('@hapi/hapi/package.json')
// }
// catch (err) {
// var pkg = require('hapi/package.json')
// }
// var version = parseInt(pkg.version.split('.')[0]) >= 17 ? 17 : 16
// }
return version
? require(`./lib/handler/${handler}-${version}`)(rest)
: require(`./lib/handler/${handler}`)(rest)
}
grant.express = (options) => {
var version = 4
var handler = require(`./lib/handler/express-${version}`)
return options ? handler(options) : handler
}
// grant.koa = (options) => {
// var version =
// parseInt(require('koa/package.json').version.split('.')[0]) >= 2 ? 2 : 1
// var handler = require(`./lib/handler/koa-${version}`)
// return options ? handler(options) : handler
// }
// grant.hapi = (options) => {
// try {
// var pkg = require('@hapi/hapi/package.json')
// }
// catch (err) {
// var pkg = require('hapi/package.json')
// }
// var version = parseInt(pkg.version.split('.')[0]) >= 17 ? 17 : 16
// var handler = require(`./lib/handler/hapi-${version}`)
// return options ? handler(options) : handler
// }
;[
'fastify', 'curveball',
'node', 'aws', 'azure', 'gcloud', 'vercel'
].forEach((provider) => {
grant[provider] = (options) => {
var handler = require(`./lib/handler/${provider}`)
return options ? handler(options) : handler
}
})
grant.default = grant
module.exports = grant I am using serverless-bundle which uses serverless-webpack under the hood and I am thinking that webpack might be interacting oddly with grant. Just a thought. |
Thanks for the detailed bug report 👍 Yes, it is an issue with the bundler because Grant loads optional dependencies at runtime where the bundler tries to resolve all Not sure if or how this will be possible to fix because by design Grant was never meant to be bundled, but lets keep this issue open for now. Probably with an updated title regarding the bundling process. |
I did a few improvements on the imports, now all var path = require('path')
var webpack = require('webpack')
// suppresses the warnings in the console
var ignore = new webpack.IgnorePlugin({
resourceRegExp: /(koa|hapi)\/package\.json/
})
module.exports = {
entry: './examples/grant.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'webpack.bundle.js',
},
target: 'node',
plugins: [ignore],
mode: 'production',
} |
I am using the aws handler and when running using serverless-offline, I am getting the following errors:
Here is a condensed version of the code I am using:
Neither of the errors seem to have any impact, however I am wondering if you have noticed this before. I couldn't find any similar issues so this might just be a side-effect of using serverless-offline or something similar.
If there is anything else I can do to help please let me know. Thanks and happy holidays 🎆 🎉
The text was updated successfully, but these errors were encountered: