question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(@aws-cdk/aws-cognito): import 'punycode/'

See original GitHub issue

❓ General Issue

The Question

about “@aws-cdk/aws-cognito/lib/user-pool.ts”. I don’t think punycode’s trailing slash is necessary.

current code
import { toASCII as punycodeEncode } from 'punycode/';
expected code
import { toASCII as punycodeEncode } from 'punycode';

Environment

  • CDK CLI Version: v1.100.0
  • Module Version:
  • Node.js Version:
  • OS:
  • Language (Version):

Other information

An error occurred when importing ‘@aws-cdk/aws-cognito’ in the Lambda function handler.

Lambda Runtime Error
{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'punycode/'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    ...
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
danielholmescommented, Jul 19, 2021

I had this error as well and was able to fix it through some code changes. For me it was an error in my code organisation.

In my case it was to do with mixing devDependencies/cdk code with my runtime lambda code.

e.g. I had some files similar to:

package.json

{
 ...
  "devDependencies": {
    "@aws-cdk/aws-lambda-nodejs": "^1.114.0",
    "@aws-cdk/aws-cognito": "^1.114.0",
    ...
  }
}

users/index.ts

export { default as Construct } from "./construct";
export { default as getViewerResolver } from "./getViewerResolver";

users/construct.ts

import { UserPool } "@aws-cdk/aws-cognito"
// ...

api/construct.ts

// ...
class ApiConstruct extends Construct {
  constructor() {
    //...
    const defaultResolverLambda = new NodejsFunction(
      this,
      "DefaultGraphQlResolver",
      {
        runtime: Runtime.NODEJS_14_X,
        entry: path.join(__dirname, "..", "users", "index.ts"),
        handler: "getViewerResolver"
      }
    );
  }
}

including that users/index.ts file as an entry therefore included the users/construct.ts which tried to include some cdk cognito code which wasn’t part of my runtime dependencies.

So the fix was to make sure my construct/cdk code was completely separate from my runtime lambda code.

0reactions
gorjusborgcommented, Jan 20, 2022

Thanks for posting this @danielholmes, I had the same issue.

We had some Custom::Trigger that would run to populate user data on deploy. Unfortunately, the lambda handler was thrown in the same module as some CDK code that was loosely related. This caused esbuild to bundle aws-cdk-lib/aws-cognito in the lambda, which declares a ‘bundledDependency’ on ‘punycode/’, but apparently it isn’t bundled in the cdk v2 library (hence the require).

This popped up on upgrade to CDK v2 after working with CDK v1 with an error like Runtime.ImportModuleError: Error: Cannot find module 'punycode/'.

The answer for me was to isolate the lambda code so that NO CDK code was referenced (even transitively) by module imports.

Read more comments on GitHub >

github_iconTop Results From Across the Web

punycode - npm
A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.
Read more >
Punycode | Node.js v19.3.0 Documentation
Punycode is a character encoding scheme defined by RFC 3492 that is primarily intended for use in Internationalized Domain Names. Because host names...
Read more >
punycode is deprecated in npm - what should I replace it with?
I'm using the npm module punycode in my Angular project. ... Try import punycode from "punycode/"; for example.
Read more >
What is the Punycode in Node.js ? - GeeksforGeeks
Punycode is a special encoding syntax that is specifically used to convert Unicode characters (UTF-8) to ASCII, which is nothing but the ...
Read more >
Working with IDN domains and Punycode in JavaScript
A tool that converts a text with special characters (Unicode) to the Punycode encoding (just ASCII). Used for internationalized domain names (IDN).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found