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

yaml do not define a valid './types' target

Open npxcomplete opened this issue 6 years ago • 15 comments

Running cdk deploy

Error Log

Error: Package exports for 'C:\Users\kpratt\AppData\Roaming\npm\node_modules\aws-cdk\node_modules\yaml' do not define a valid './types' target at resolveExportsTarget (internal/modules/cjs/loader.js:621:9) at applyExports (internal/modules/cjs/loader.js:502:14) at resolveExports (internal/modules/cjs/loader.js:551:12) at Function.Module._findPath (internal/modules/cjs/loader.js:657:22) at Function.Module._resolveFilename (internal/modules/cjs/loader.js:960:27) at Function.Module._load (internal/modules/cjs/loader.js:855:27) at Module.require (internal/modules/cjs/loader.js:1033:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (C:\Users\kpratt\AppData\Roaming\npm\node_modules\aws-cdk\lib\serialize.ts:5:19) at Module._compile (internal/modules/cjs/loader.js:1144:30)

Environment

  • CLI Version : 6.13.4
  • Framework Version: 1.26 & 1.27
  • OS : Windows
  • Language : Java

Other


This is :bug: Bug Report

npxcomplete avatar Mar 08 '20 04:03 npxcomplete

I've got the same with TS(v.1.27) but it happens only when I've tried to run it by npm. a workaround that works for me is to run it globally.

lielran avatar Mar 09 '20 09:03 lielran

npm version: 6.13.4 framework version: 1.27 os: linux language: typescript

Same error with node version 13.3 With node version 12.16.1 (LTS), the error is gone. Everything works fine.

BenoitDel avatar Mar 09 '20 09:03 BenoitDel

I get the same error with npm: '6.13.2' MAC OS: 10.14.6

ps ..

looks like it is something todo with yaml module. I replaced the "yaml" module "/node_modules/aws-cdk/node_modules/yaml" with version "1.7.2" and it worked !

vedat227 avatar Mar 09 '20 10:03 vedat227

Had the same with npm version: 6.13.4 framework version 1.27 & 1.26 os: WSL language: Java Looks like it works with npm 6.13.6 (node v13.7.0)

liamor avatar Mar 09 '20 11:03 liamor

Adding "yaml": "1.7.2" to my package.json and running npm i solved it for me

spg avatar Mar 09 '20 15:03 spg

I am getting the same error when runing cdk init --language typescript

Error: Package exports for '/usr/local/lib/node_modules/cdk/node_modules/yaml' do not define a valid './types' target
    at resolveExportsTarget (internal/modules/cjs/loader.js:545:13)
    at applyExports (internal/modules/cjs/loader.js:459:14)
    at resolveExports (internal/modules/cjs/loader.js:508:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:577:20)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
    at Function.Module._load (internal/modules/cjs/loader.js:785:27)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/cdk/node_modules/aws-cdk/lib/serialize.ts:5:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

Update:

It got worked for me after updating node to 13.10.1 and npm 6.13.7

rahulrkr08 avatar Mar 09 '20 15:03 rahulrkr08

Suspected as P0, needs investigation

eladb avatar Mar 09 '20 18:03 eladb

@npxcomplete Can you paste the output of a couple of things for me

1: cdk --version 2: cdk deploy --verbose

I suspect a version mismatch somewhere.

remember to redact any sensitive information that may be in this output

MrArnoldPalmer avatar Mar 09 '20 18:03 MrArnoldPalmer

Same issue here after upgrading.

$ cdk --version
1.19.0 (build 5597bbe)
$ npm upgrade
   ╭────────────────────────────────────────────────────────────────╮
   │                                                                │
   │      New minor version of npm available! 6.13.4 → 6.14.2       │
   │   Changelog: https://github.com/npm/cli/releases/tag/v6.14.2   │
   │               Run npm install -g npm to update!                │
   │                                                                │
   ╰────────────────────────────────────────────────────────────────╯

$ npm install -g npm
+ [email protected]
$ npm install -g aws-cdk
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
/usr/local/bin/cdk -> /usr/local/lib/node_modules/aws-cdk/bin/cdk
+ [email protected]
added 234 packages from 227 contributors in 9.41s
$ cdk --version
Error: Package exports for '/usr/local/lib/node_modules/aws-cdk/node_modules/yaml' do not define a valid './types' target
    at resolveExportsTarget (internal/modules/cjs/loader.js:614:9)
    at applyExports (internal/modules/cjs/loader.js:499:14)
    at resolveExports (internal/modules/cjs/loader.js:548:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:650:22)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:948:27)
    at Function.Module._load (internal/modules/cjs/loader.js:854:27)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/aws-cdk/lib/serialize.ts:5:19)
    at Module._compile (internal/modules/cjs/loader.js:1128:30)

deki avatar Mar 10 '20 14:03 deki

@deki I'm not able to reproduce this. Tried across multiple versions of node/npm.

It looks like everyone reporting issues here is using their system's global NodeJS installation, since error dir is reported as /usr/local/lib/node_modules/aws-cdk/node_modules. I'm not sure why that would be causing issues here, but its commonly the source of permission problems.

Some debugging tips:

  1. If you delete your global node_modules directory and reinstall aws-cdk, does the issue persist?
  2. If you run aws-cdk from your project's local node_modules dir, does the issue persist?
  3. If you install nvm and use a user level install of Node/Npm, does the issue persist?

We recommend using nvm generally speaking because it helps avoid a lot of similar issues.

MrArnoldPalmer avatar Mar 10 '20 17:03 MrArnoldPalmer

Worked for me after upgrading from node 13.1.0 to node 13.10.1.

pd5rm avatar Mar 10 '20 21:03 pd5rm

@MrArnoldPalmer I am using NVM and it works for me on Node 13.7.0 and fails on 13.5.0

liamor avatar Mar 10 '20 22:03 liamor

Worked after upgrade from node 13.6.0 to 13.10.1, npm 6.13.7

ndndien avatar Mar 11 '20 03:03 ndndien

@liamor thanks, that pointed me in the right direction.

It looks like there is an issue with the yaml dependency and the exports key, which is used for ESM module support. This occurs on CDK versions going back quite a ways.

If you need to use cdk with NodeJS 13.0.0-13.6.0, you can use the --experimental-modules flag, ie: node --experimental-modules /path/to/cdk --version. Otherwise, I'd recommend using node 12 or > 13.7.0 until we figure out the best course here. It doesn't seem like we can change our export strategy currently since the top level CJS export doesn't expose the types module in yaml.

Here is the issue in the yaml repo with more info https://github.com/eemeli/yaml/issues/140

MrArnoldPalmer avatar Mar 11 '20 03:03 MrArnoldPalmer

Bumping the yaml version dependency should fix this issue, this will be in the next release. https://github.com/aws/aws-cdk/pull/6670

MrArnoldPalmer avatar Mar 11 '20 20:03 MrArnoldPalmer