projen
projen copied to clipboard
Unable to add NPM dependency to `AwsCdkConstructLibrary` project // confusing error message
Hi,
I cannot add express
NPM library as dependency to my AwsCdkConstructLibrary
project.
If this is intended could you please improve error message?
Projen version: v0.56.26
My projen file:
const { awscdk } = require('projen');
const project = new awscdk.AwsCdkConstructLibrary({
...
deps: ['express'],
});
project.synth();
Error message:
[2022-05-21T21:15:10.095] [ERROR] jsii/package-info - Unable to find a JSII dependency named "express" as "^4.18.1".
If you meant to include a non-JSII dependency, try adding it to bundledDependencies instead.
Error: Error: Error loading /Users/yerzhan/lambda-runtime-upgrader-cdk/node_modules/express/.jsii: Error:
/Users/yerzhan/lambda-runtime-upgrader-cdk/node_modules/express/.jsii: ENOENT: no such file or directory, open
According to the docs I should be able to do it:
(property) NodePackageOptions.deps?: string[] Runtime dependencies of this module. The recommendation is to only specify the module name here (e.g. express). This will behave similar to yarn add or npm install in the sense that it will add the module as a dependency to your package.json file with the latest version (^). You can specify semver requirements in the same syntax passed to npm i or yarn add (e.g. express@^2) and this will be what you package.json will eventually include. @example [ 'express', 'lodash', 'foo@^2' ] @default [] @featured
I assume you use it inside a lamdba function and not to export it on your cdk construct interfaces. Therefor add it to devDeps
and let NodejsFunction bundle your lambda with express middleware.
No, I am not using Lambda function. I cannot simply add any dependency at all to my empty AwsCdkConstructLibrary
project.
Nothing works. E.g.:
deps: [
'lodash',
],
If this is intended could you please update docs and error message? Because your docs say that I should be able to do this.
It's correct that you can't add express
or lodash
as dependencies of an AwsCdkConstructLibrary
in that way. They are not AWS CDK constructs itself, so you won't export them as an interface of another construct. As the error message states, you should put them in bundledDeps
or maybe devDeps
. The only use case I can imagine, is using express
as runtime dependency, which gets 'compiled' into a lambda or docker container at build time. As long as you don'T export any interface of lodash
, it's definitly a bundledDeps
, if just used as an internal helper library of your construct. Maybe you can give an example of what you are trying to achieve. For general questions around cdk go to this slack https://cdk.dev/ there are a lot of nice and helpful people
Works as designed by jsii. Feel free to open an issue/discussion at aws/jsii.