aws-cdk: yaml do not define a valid './types' target

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.<anonymous> (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 Report

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@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

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

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 !