-
Notifications
You must be signed in to change notification settings - Fork 412
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
When I add an external library (as a directory), there is an error installing dependencies of the package. #632
Comments
same issue.
also in my case the issue is caused by a private repository in package.json with |
Facing this as well. Any updates? |
@angelgarrido @lenamikaze Try running |
@ssanri |
I'm having a similar error (maybe is the same related by the author). We're build a lambda layer to provide shared node_modules packages and a common Database connection logic shared across all lambdas that are exported as a module and required as When running
Solved it by addind webpack: {
includeModules: {
// Modules provided by lambda layer
forceExclude: [
'@internal/somepackage1',
'@internal/somepackage2',
'mongodb',
'mongodb-client-encryption',
'mongoose',
'', // <--------------------------
],
}, Project configuration files:
const serverlessConfiguration: AWS = {
frameworkVersion: '3',
plugins: [
'serverless-webpack',
'serverless-offline',
],
provider: {
name: 'aws',
runtime: 'nodejs14.x',
},
package: { individually: true },
custom: {
webpack: {
includeModules: {
// Modules provided by lambda layer
forceExclude: [
'@internal/somepackage1',
'@internal/somepackage2',
'mongodb',
'mongodb-client-encryption',
'mongoose',
],
},
},
},
}
module.exports = serverlessConfiguration
const path = require('path')
const slsw = require('serverless-webpack')
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
module.exports = {
context: __dirname,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
devtool: slsw.lib.webpack.isLocal ? 'eval-cheap-module-source-map' : 'source-map',
resolve: {
extensions: ['.js', '.mjs', '.json', '.ts'],
symlinks: false,
cacheWithContext: false,
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
sourceMapFilename: '[file].map',
},
optimization: {
concatenateModules: false,
},
target: 'node',
externals: [
nodeExternals(),
{ '/opt/nodejs/external-lib-provided-by-lambda-layer': 'commonjs2 /opt/nodejs/external-lib-provided-by-lambda-layer' },
],
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{
test: /\.(tsx?)$/,
loader: 'ts-loader',
exclude: [
[
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '.serverless'),
path.resolve(__dirname, '.webpack'),
],
],
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
} Project's {
"name": "somepackage",
"version": "1.0.0",
"main": "serverless.ts",
"scripts": {
"start": "cross-env NODE_ENV=test serverless offline start --stage dev",
"deploy": "npx serverless deploy"
},
"dependencies": {
"@middy/secrets-manager": "^2.5.7"
},
"optionalDependencies": { // Modules provided by lambda layer
"@internal/somepackage1": "0.0.18-beta",
"@internal/somepackage2": "0.0.3-beta",
"mongodb": "4.3.1",
"mongodb-client-encryption": "^2.0.0",
"mongoose": "^6.2.3"
},
"devDependencies": {
"@serverless/typescript": "^3.3.0",
"@types/aws-lambda": "^8.10.92",
"@types/jest": "^27.4.1",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"aws-sdk": "^2.1081.0",
"cross-env": "^7.0.3",
"eslint": "^8.10.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.4.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.5.1",
"jest-mock": "^27.5.1",
"prettier": "^2.5.1",
"serverless": "^3.7.1",
"serverless-offline": "^8.5.0",
"serverless-plugin-typescript": "^2.1.1",
"serverless-vpc-plugin": "^1.0.4",
"serverless-webpack": "^5.6.1",
"ts-jest": "^27.1.3",
"ts-loader": "^9.2.6",
"ts-node": "^10.5.0",
"typescript": "4.5.5",
"webpack": "^5.70.0",
"webpack-node-externals": "^3.0.0"
}
}
{
"name": "packagename",
"version": "1.0.0",
"description": "Packaged externals for somepackage",
"private": true,
"scripts": {},
"dependencies": {
"@middy/secrets-manager": "^2.5.7",
"": ""
}
} |
Having the same troubles right now. Anyone found a workaround I would love to finish my feature 🙂 Edit: Could we have a fallback like if (!moduleVersion) {
try {
moduleVersion = require(`${module.external}/package.json`).version;
} catch {}
}
if (!moduleVersion) {
try {
// Need to remove potential nested subfolders and file from the path
const modulePath = require.resolve(module.external).replace(new RegExp(`${module.external}/.*$`), module.external);
moduleVersion = require(`${modulePath}/package.json`).version;
} catch {}
} |
Also facing this, it's adding several
|
In my case I think it's related to passing a custom node-externals function that it's not recognizing, which I did as a workaround for liady/webpack-node-externals#95. This messes up with the logic totally:
This works:
|
This is a (Bug Report)
Description
For bug reports:
I'm using serverless-webpack with a project that uses a lambda layer made with typescript for common modules and code.
We are deploying the layer in remote and in local in "/opt" directory so i want to exclude this directories on the Webpack bundle.
For doing so, I've added our directory as a regular expression to the externals declaration of Webpack config.
This works fine, as the dependency is treated as external, but when is trying to install dependencies it generates a 'empty' package.json package name & package version and the npm install to for creating dependencies fails.
On line 128 of packExternalModules.js in serverless-webpack package is where it tries to push the module without name or version.
I've used a workaround with forceExclude in serverless.yml
As it is an external directories with my own packages, I expect to be identified as that and don't try to install them. Also detect the name and version correctly.
This is my Webpack.config.js file
And it has created the file ./dist/dependencies/package.json with this content:
For feature proposals:
It should be an easier way to exclude directories without try to install it as a dependency.
Or add an optional boolean parameter to externals to forceExclude on dependenciesPackage
Similar or dependent issue(s):
Additional Data
"^5.3.4"
"^4.43.0",
Framework Core: 1.77.0
Plugin: 3.6.18
SDK: 2.3.1
Components: 2.33.0
Dockerized linux alpine
The text was updated successfully, but these errors were encountered: