aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

aws-lambda-nodejs empties node_modules folder when building functions in different directories

Open msimpsonnz opened this issue 6 years ago • 4 comments

aws-lambda-nodejs empties node_modules folder when building functions in different directories

Reproduction Steps

mkdir func cd func npm init touch index.ts cd .. mkdir cdk cd cdk cdk init --language typescript this is the cdk-stack.ts

import * as cdk from '@aws-cdk/core';
import lambda = require('@aws-cdk/aws-lambda-nodejs');

export class CdkStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new lambda.NodejsFunction(this, 'MyFunction', {
      entry: '../func/lam/index.ts',
      handler: 'handler'
    });
  }
}

Error Log

bin/cdk.ts:3:22 - error TS2307: Cannot find module '@aws-cdk/core'.

When I check the node_modules folder in the cdk directory only has a typescript folder

Environment

  • **CLI Version :
  • **Framework Version: 1.27.0
  • **OS : macos
  • **Language : typescript

Other


This is :bug: Bug Report

msimpsonnz avatar Mar 12 '20 04:03 msimpsonnz

hey @msimpsonnz, I'm not able to reproduce the error.

From which folder are you running cdk synth?

When I check the node_modules folder in the cdk directory only has a typescript folder

I think that it should be the case for your func folder.

Did you install parcel-bundler locally in the cdk folder?

image

jogold avatar Mar 12 '20 08:03 jogold

Thanks, I’m running synth from the cdk folder Yep I have install the pre reqs

msimpsonnz avatar Mar 12 '20 08:03 msimpsonnz

Can you share your exact folder structure and both package.json files? Is aws-cdk installed globally? Does parcel build successfully? Do you see a index.js file in func/.build/<hash>/?

jogold avatar Mar 12 '20 08:03 jogold

Looks like it was NPM upgraded to latest version and is good

msimpsonnz avatar Mar 13 '20 21:03 msimpsonnz