Skip to content
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

importing the aws-sdk results in a module not found error #1636

Closed
1 of 4 tasks
richardhboyd opened this issue May 7, 2020 · 1 comment · Fixed by #1651
Closed
1 of 4 tasks

importing the aws-sdk results in a module not found error #1636

richardhboyd opened this issue May 7, 2020 · 1 comment · Fixed by #1651
Assignees
Labels
bug This issue is a bug. language/typescript Related to Typescript code p2

Comments

@richardhboyd
Copy link

richardhboyd commented May 7, 2020

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)

General Information

What is the problem?

running npx tsc works correctly and. generates the expected files, but running npx jsii or npm run build (which references jsii) fails.
my index.ts file:

import {
    ClientRequestToken,
    LogicalResourceId,
    NextToken,
} from 'aws-sdk/clients/cloudformation';


export class HelloJsii {
  public sayHello(name: string) {
    return `Hello, ${name}!`;
  }
}

Verbose Log

CrossAccountRole-Isengard:~/environment/jsii-rpdk $ npm run build --verbose
npm info it worked if it ends with ok
npm verb cli [ '/home/ec2-user/.nvm/versions/node/v10.20.1/bin/node',
npm verb cli   '/home/ec2-user/.nvm/versions/node/v10.20.1/bin/npm',
npm verb cli   'run',
npm verb cli   'build',
npm verb cli   '--verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'prebuild', 'build', 'postbuild' ]
npm info lifecycle [email protected]~prebuild: [email protected]
npm info lifecycle [email protected]~build: [email protected]

> [email protected] build /home/ec2-user/environment/jsii-rpdk
> jsii

Error: Error: Unable to locate module: aws-sdk
    at _tryResolveAssembly (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/lib/project-info.js:200:15)
    at _loadDependencies (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/lib/project-info.js:125:21)
    at Object.loadProjectInfo (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/lib/project-info.js:63:32)
    at /home/ec2-user/environment/jsii-rpdk/node_modules/jsii/bin/jsii.js:45:46
    at Object.<anonymous> (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/bin/jsii.js:62:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm verb lifecycle [email protected]~build: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~build: PATH: /home/ec2-user/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ec2-user/environment/jsii-rpdk/node_modules/.bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/ec2-user/.nvm/versions/node/v10.20.1/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3@global/bin:/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/ec2-user/.rvm/gems/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3@global/bin:/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3@global/bin:/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin:/usr/local/bin:/bin:/usr/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.rvm/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/usr/local/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.rvm/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/opt/aws/bin:/usr/local/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.rvm/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
npm verb lifecycle [email protected]~build: CWD: /home/ec2-user/environment/jsii-rpdk
npm info lifecycle [email protected]~build: Failed to exec build script
npm verb stack Error: [email protected] build: `jsii`
npm verb stack Exit status 255
npm verb stack     at EventEmitter.<anonymous> (/home/ec2-user/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
npm verb stack     at EventEmitter.emit (events.js:198:13)
npm verb stack     at ChildProcess.<anonymous> (/home/ec2-user/.nvm/versions/node/v10.20.1/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack     at ChildProcess.emit (events.js:198:13)
npm verb stack     at maybeClose (internal/child_process.js:982:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
npm verb pkgid [email protected]
npm verb cwd /home/ec2-user/environment/jsii-rpdk
npm verb Linux 4.14.173-106.229.amzn1.x86_64
npm verb argv "/home/ec2-user/.nvm/versions/node/v10.20.1/bin/node" "/home/ec2-user/.nvm/versions/node/v10.20.1/bin/npm" "run" "build" "--verbose"
npm verb node v10.20.1
npm verb npm  v6.14.4
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! [email protected] build: `jsii`
npm ERR! Exit status 255
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 255, true ]
npm timing npm Completed in 511ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ec2-user/.npm/_logs/2020-05-07T01_11_26_116Z-debug.log

My node_module:

CrossAccountRole-Isengard:~/environment/jsii-rpdk $ ls node_modules/aws-sdk/
apis        buildspec.yml  clients  dist-tools   global.js   index.js  LICENSE.txt  package.json     README.md  vendor
browser.js  CHANGELOG.md   dist     global.d.ts  index.d.ts  lib       NOTICE.txt   react-native.js  scripts

My package.json:

  "devDependencies": {
    "@types/node": "^13.13.5",
    "aws-sdk": "^2.671.0",
    "jsii": "^1.4.1",
    "jsii-pacmak": "^1.4.1"
  },

Edit

I tried again with the latest 1.5.0 release and the error is still happening.

package.json

  "devDependencies": {
    "@types/node": "^13.13.5",
    "aws-sdk": "^2.671.0",
    "jsii": "1.5.0",
    "jsii-pacmak": "1.5.0"
  },

index.ts

import AWS from 'aws-sdk';

export class HelloJsii {
  public sayHello(name: string) {
    return `Hello, ${name}!`;
  }
}

--verbose jsii output

npm info it worked if it ends with ok
npm verb cli [
npm verb cli   '/home/ec2-user/.nvm/versions/node/v12.16.3/bin/node',
npm verb cli   '/home/ec2-user/.nvm/versions/node/v12.16.3/bin/npm',
npm verb cli   'run',
npm verb cli   'build',
npm verb cli   '--verbose'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'prebuild', 'build', 'postbuild' ]
npm info lifecycle [email protected]~prebuild: [email protected]
npm info lifecycle [email protected]~build: [email protected]

> [email protected] build /home/ec2-user/environment/jsii-rpdk
> jsii

Error: Error: Unable to locate module: aws-sdk
    at _tryResolveAssembly (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/lib/project-info.js:200:15)
    at _loadDependencies (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/lib/project-info.js:125:21)
    at Object.loadProjectInfo (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/lib/project-info.js:63:32)
    at /home/ec2-user/environment/jsii-rpdk/node_modules/jsii/bin/jsii.js:45:46
    at Object.<anonymous> (/home/ec2-user/environment/jsii-rpdk/node_modules/jsii/bin/jsii.js:62:3)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
npm verb lifecycle [email protected]~build: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~build: PATH: /home/ec2-user/.nvm/versions/node/v12.16.3/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ec2-user/environment/jsii-rpdk/node_modules/.bin:/home/ec2-user/.nvm/versions/node/v12.16.3/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/ec2-user/.rvm/gems/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3@global/bin:/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/ec2-user/.rvm/gems/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3@global/bin:/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3/bin:/home/ec2-user/.rvm/gems/ruby-2.6.3@global/bin:/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin:/usr/local/bin:/bin:/usr/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.rvm/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/usr/local/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.rvm/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/opt/aws/bin:/usr/local/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.rvm/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
npm verb lifecycle [email protected]~build: CWD: /home/ec2-user/environment/jsii-rpdk
npm info lifecycle [email protected]~build: Failed to exec build script
npm verb stack Error: [email protected] build: `jsii`
npm verb stack Exit status 255
npm verb stack     at EventEmitter.<anonymous> (/home/ec2-user/.nvm/versions/node/v12.16.3/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
npm verb stack     at EventEmitter.emit (events.js:310:20)
npm verb stack     at ChildProcess.<anonymous> (/home/ec2-user/.nvm/versions/node/v12.16.3/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack     at ChildProcess.emit (events.js:310:20)
npm verb stack     at maybeClose (internal/child_process.js:1021:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
npm verb pkgid [email protected]
npm verb cwd /home/ec2-user/environment/jsii-rpdk
npm verb Linux 4.14.173-106.229.amzn1.x86_64
npm verb argv "/home/ec2-user/.nvm/versions/node/v12.16.3/bin/node" "/home/ec2-user/.nvm/versions/node/v12.16.3/bin/npm" "run" "build" "--verbose"
npm verb node v12.16.3
npm verb npm  v6.14.4
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! [email protected] build: `jsii`
npm ERR! Exit status 255
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 255, true ]
npm timing npm Completed in 419ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ec2-user/.npm/_logs/2020-05-07T19_34_44_557Z-debug.log
@richardhboyd richardhboyd added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 7, 2020
@SomayaB SomayaB added the language/typescript Related to Typescript code label May 11, 2020
@RomainMuller
Copy link
Contributor

Non-jsii-enabled modules must be bundled (bundleDependencies). This error message isn't quite ideal, let me prepare a PR to actually improve this a bit.

RomainMuller added a commit that referenced this issue May 12, 2020
Instead of outputting a very terse 'Unable to locate module', which misleads users into believing
the module cannot be resolved by the compiler, use a longer error message that clearly states the
jsii Assembly could not be located, and that non-jsii dependencies must be bundled.

Fixes #1636
@RomainMuller RomainMuller added p2 and removed needs-triage This issue or PR still needs to be triaged. labels May 12, 2020
@mergify mergify bot closed this as completed in #1651 May 12, 2020
mergify bot pushed a commit that referenced this issue May 12, 2020
#1651)

Instead of outputting a very terse 'Unable to locate module', which misleads users into believing
the module cannot be resolved by the compiler, use a longer error message that clearly states the
jsii Assembly could not be located, and that non-jsii dependencies must be bundled.

Fixes #1636
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. language/typescript Related to Typescript code p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants