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

Unexpected token error with cdk deploy on an existing stack project (written in Java) #20678

Closed
ShubhamSrivastava93 opened this issue Jun 9, 2022 · 18 comments
Assignees
Labels
bug This issue is a bug. jsii This issue originates in jsii, or this feature must be implemented in jsii. p1 package/tools Related to AWS CDK Tools or CLI

Comments

@ShubhamSrivastava93
Copy link

ShubhamSrivastava93 commented Jun 9, 2022

Describe the bug

Hi I've an existing stack project written in Java. So far I've been deploying it using cdk deploy command and it was working as expected but suddenly since yesterday (with no change) I started getting error regardless of what the CDK template is. I tried with node versions v14.17.6, v10.16.3 and v10.19.0 but no luck. I doubt if other cdk commands like synth would also work or not

Expected Behavior

cdk deploy should generate cft and deploy it to AWS, like it was doing so far

Current Behavior

Getting below error

Exception in thread "main" software.amazon.jsii.JsiiException: Child process exited unexpectedly!
at software.amazon.jsii.JsiiRuntime.readNextResponse(JsiiRuntime.java:330)
at software.amazon.jsii.JsiiRuntime.handshake(JsiiRuntime.java:310)
at software.amazon.jsii.JsiiRuntime.startRuntimeIfNeeded(JsiiRuntime.java:300)
at software.amazon.jsii.JsiiRuntime.getClient(JsiiRuntime.java:346)
at software.amazon.jsii.JsiiEngine.getClient(JsiiEngine.java:150)
at software.amazon.jsii.JsiiEngine.loadModule(JsiiEngine.java:188)
at software.amazon.jsii.JsiiEngine.loadModule(JsiiEngine.java:185)
at software.amazon.jsii.JsiiEngine.createNewObject(JsiiEngine.java:597)
at software.amazon.awscdk.core.App.(App.java:86)
/tmp/jsii-java-runtime5137197359112545983/bin/jsii-runtime.js:3666
this.untested = opts.untested ?? false;
SyntaxError: Unexpected token ?
at Module._compile (internal/modules/cjs/loader.js:723:23)
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)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Subprocess exited with error 1

Reproduction Steps

Any aws stack project written in java when trying to deploy using cdk deploy command

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.20.0

Framework Version

No response

Node.js Version

v14.17.6

OS

linux

Language

Java

Language Version

No response

Other information

No response

@ShubhamSrivastava93 ShubhamSrivastava93 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 9, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Jun 9, 2022
@ShubhamSrivastava93 ShubhamSrivastava93 changed the title Unexpected token error with cdk deploy on an existing stack (written in Java) Unexpected token error with cdk deploy on an existing stack project (written in Java) Jun 9, 2022
@mickael-caro-sonarsource
Copy link

mickael-caro-sonarsource commented Jun 9, 2022

Same issue here with Node 12 and CDK (Python) 2.27.0

@Onkar-Kandalgaonkar
Copy link

I am also getting the same error on local linux machine and also on jenkins pipeline.
Node v10.19.0, aws-cdk 1.132.0

@mickael-caro-sonarsource

Bumping to Node 16 seems to have mitigated the issue.

@GabrielZabielski
Copy link

GabrielZabielski commented Jun 9, 2022

Same issue with:
$ python -V
Python 3.8.12
$ cdk --version
1.135.0 (build 3825f59)
$ virtualenv .env
created virtual environment CPython3.8.12.final.0-64 in 563ms

The same code worked yesterday, currently:

$ cdk synth -c environment=${env} -c region=eu-central-1 --app "python3 app_infra.py" '*'
b'/tmp/tmpuitsvh9j/bin/jsii-runtime.js:3666\n'
b'                this.untested = opts.untested ?? false;\n'
b'                                               ^\n'
b'\n'
b"SyntaxError: Unexpected token '?'\n"
b'    at wrapSafe (internal/modules/cjs/loader.js:915:16)\n'
b'    at Module._compile (internal/modules/cjs/loader.js:963:27)\n'
b'    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)\n'
b'    at Module.load (internal/modules/cjs/loader.js:863:32)\n'
b'    at Function.Module._load (internal/modules/cjs/loader.js:708:14)\n'
b'    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:[60](https://domain.com/main/main-app/infra/-/jobs/9143493#L60):12)\n'
b'    at internal/main/run_main_module.js:17:47\n'
Traceback (most recent call last):
  File "app_infra.py", line 3, in <module>
    from apps.main_infra_app import mainInfraApp
  File "/builds/bAw1WQc7/0/main/main-app/infra/cdk/apps/main_infra_app.py", line 1, in <module>
    from apps.base_app import BaseApp
  File "/builds/bAw1WQc7/0/main/main-app/infra/cdk/apps/base_app.py", line 3, in <module>
    from aspects.kms_key_rotation import KMSKeyRotationAspect
  File "/builds/bAw1WQc7/0/main/main-app/infra/cdk/aspects/kms_key_rotation.py", line 2, in <module>
    from aws_cdk import aws_iam as iam
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/aws_cdk/aws_iam/__init__.py", line 501, in <module>
    from ._jsii import *
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/aws_cdk/aws_iam/_jsii/__init__.py", line 11, in <module>
    import aws_cdk.core._jsii
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/aws_cdk/core/__init__.py", line 914, in <module>
    from ._jsii import *
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/aws_cdk/core/_jsii/__init__.py", line 11, in <module>
    import aws_cdk.cloud_assembly_schema._jsii
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/aws_cdk/cloud_assembly_schema/__init__.py", line 75, in <module>
    from ._jsii import *
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/aws_cdk/cloud_assembly_schema/_jsii/__init__.py", line 11, in <module>
    __jsii_assembly__ = jsii.JSIIAssembly.load(
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_runtime.py", line 43, in load
    _kernel.load(assembly.name, assembly.version, os.fspath(assembly_path))
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 2[69](https://domain.com/main/main-app/infra/-/jobs/9143493#L69), in load
    self.provider.load(LoadRequest(name=name, version=version, tarball=tarball))
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 338, in load
    return self._process.send(request, LoadResponse)
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_utils.py", line 24, in wrapped
    stored.append(fgetter(self))
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 333, in _process
    process.start()
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 275, in start
    self.handshake()
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 299, in handshake
    self._next_message(), _HelloResponse
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 242, in _next_message
    return json.loads(self._process.stdout.readline(), object_hook=ohook)
  File "/usr/local/lib/python3.8/json/__init__.py", line 3[70](https://domain.com/main/main-app/infra/-/jobs/9143493#L70), in loads
    return cls(**kw).decode(s)
  File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/builds/bAw1WQc7/0/main/main-app/infra/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 2[84](https://domain.com/main/main-app/infra/-/jobs/9143493#L84), in stop
    self._process.stdin.close()

@GabrielZabielski
Copy link

aws/jsii#3589

solving the problem?

@emmamoinat
Copy link

emmamoinat commented Jun 9, 2022

Seeing the same issue just started today (09/06/2022) - had been running fine in node v 8 and v 12 before today.

	at software.amazon.jsii.JsiiRuntime.readNextResponse(JsiiRuntime.java:330)
	at software.amazon.jsii.JsiiRuntime.handshake(JsiiRuntime.java:310)
	at software.amazon.jsii.JsiiRuntime.startRuntimeIfNeeded(JsiiRuntime.java:300)
	at software.amazon.jsii.JsiiRuntime.getClient(JsiiRuntime.java:346)
	at software.amazon.jsii.JsiiEngine.getClient(JsiiEngine.java:150)
	at software.amazon.jsii.JsiiEngine.loadModule(JsiiEngine.java:188)
	at software.amazon.jsii.JsiiEngine.loadModule(JsiiEngine.java:185)
	at software.amazon.jsii.JsiiEngine.createNewObject(JsiiEngine.java:597)
	at software.amazon.awscdk.core.App.<init>(App.java:86)
	at com.project.main(InfrastructureApp.kt:37)
	at com.project.InfrastructureAppKt.main(InfrastructureApp.kt)
/tmp/jsii-java-runtime9797915017993035093/bin/jsii-runtime.js:3666

                this.untested = opts.untested ?? false;
                                               ^
SyntaxError: Unexpected token ?

    at Module._compile (internal/modules/cjs/loader.js:723:23)
    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)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)```

@zhangwenjia0326
Copy link

Experiencing the same issue. For now, I added "jsii == 1.59.0" in my requirement.txt, which temporarily fixed my issue. Open to better short term solution suggestions though while this is being fixed.

@ShubhamSrivastava93
Copy link
Author

Bumping to Node 16 seems to have mitigated the issue.

upgrading to node 16 worked but just wondering how a specific combination of cdk, node and other dependent libraries versions suddenly stopped working

@peterwoodworth
Copy link
Contributor

We dropped support for node 12 in our latest JSII release https://github.com/aws/jsii/releases/tag/v1.60.0

Then released a hotfix because of the ?? issue aws/jsii#3588

This issue should be fixed?

@peterwoodworth peterwoodworth added p1 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. jsii This issue originates in jsii, or this feature must be implemented in jsii. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 9, 2022
@emmamoinat
Copy link

emmamoinat commented Jun 10, 2022

I tried both jsii at version 1.60.0 and 1.60.1 but sadly I am still seeing errors.

For me the error is coming when I call something like:
InstanceType("r5.4xlarge")

which is import software.amazon.awscdk.services.ec2.InstanceType

And it seems to fail here in JsiiRuntime:

        try {
            String responseLine = this.stdout.readLine();
            if (responseLine == null) {
                throw new JsiiException("Child process exited unexpectedly!");
            }
            final JsonNode response = JsiiObjectMapper.INSTANCE.readTree(responseLine);
            JsiiRuntime.notifyInspector(response, MessageInspector.MessageType.Response);
            return response;
        } catch (IOException e) {
            throw new JsiiException("Unable to read reply from jsii-runtime: " + e.toString(), e);
        }
    }

because responseLine is null.

This only happens on node 12 but I don't have the ability currently to update my pipeline to node 14 or 16 so need a fix.

Versions:
Now using node v12.8.0 (64-bit)
cdkVersion = "1.36.1"
jsiiVersion = "1.60.1"

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 10, 2022
@ayachnes2
Copy link

ayachnes2 commented Jun 10, 2022

@emmapatterson I am also using CDK with Java, and I'm using node 12.22.12 and CDK 1.130.0. I was in a similar situation as you except I tried downgrading the transient depdendency software.amazon.jsii:jsii-runtime:1.59.0, getting the following error message:

Exception in thread "main" software.amazon.jsii.JsiiException: Unexpected token '?'
jsii-kernel-PGFecQ/node_modules/constructs/lib/construct.js:501
        const nodeFactory = options.nodeFactory ?? { createNode: (host, nodeScope, nodeId) => new Node(host, nodeScope, nodeId) };

This was happening because of the transient dependency software.constructs:constructs:3.4.32, which is a breaking minor version change for node 12. Downgrading software.constructs:constructs:3.4.32 to software.constructs:constructs:3.4.31 fixed the issue.

So, in summary, I can confirm that the following works with node 12.22.12:

  1. Downgrade software.amazon.jsii:jsii-runtime to 1.59.0
  2. Downgrade software.constructs:constructs to 3.4.31

With a build system like gradle that looks something like:

configurations.all {
  resolutionStrategy {
    force 'software.amazon.jsii:jsii-runtime:1.59.0'
    force 'software.constructs:constructs:3.4.31'
  }
}

@emmamoinat
Copy link

@ayachnes2 you are my hero.

@kknd4eva
Copy link

Can confirm that updating from NodeJS 12.x to 14.x resolved this issue for us. We have a CICD pipeline in Azure DevOps using CDK. This error only started occurring a few days ago.

2022-06-15 17_38_12-Commit da958db9_ Update CICD NodeJs from 12 x to 14 x  - Repos

@rix0rrr
Copy link
Contributor

rix0rrr commented Jul 7, 2022

Duplicate of #20739

@rix0rrr rix0rrr marked this as a duplicate of #20739 Jul 7, 2022
@rix0rrr rix0rrr closed this as completed Jul 7, 2022
@github-actions
Copy link

github-actions bot commented Jul 7, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@LinTechSo
Copy link

Hi, any updates ?

cdk8s import --language python
/usr/local/lib/node_modules/cdk8s-cli/node_modules/cdk8s/lib/api-object.js:28
        this.name = props.metadata?.name ?? this.chart.generateObjectName(this);
                                   ^

SyntaxError: Unexpected token '.'

@th3outcast
Copy link

@LinTechSo Did you manage to resolve the error? I have the exact same issue.

@th3outcast
Copy link

@th3outcast Upgrading to latest version of node fixes error as optional chaining was introduced in Node 14.

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. jsii This issue originates in jsii, or this feature must be implemented in jsii. p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests