ecs-logging-nodejs icon indicating copy to clipboard operation
ecs-logging-nodejs copied to clipboard

Fix TS import without esModuleInterop option

Open lundibundi opened this issue 4 years ago • 3 comments

Before this change and without esModuleInterop: true one could only import the module via

import escFormat = require('@elastic/ecs-pino-format');

After this it can also be imported with: (which is more in-line with other such "interoperability" use cases)

import * as escFormat from '@elastic/ecs-pino-format';

Refs: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-function-d-ts.html

lundibundi avatar Aug 25 '21 17:08 lundibundi

:grey_exclamation: Build Aborted

The PR is not allowed to run in the CI yet

the below badges are clickable and redirect to their specific view in the CI or DOCS Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Reason: The PR is not allowed to run in the CI yet

  • Start Time: 2021-08-25T17:31:25.232+0000

  • Duration: 3 min 8 sec

  • Commit: ec077a79897bb44b03a3c1bb3695f1e9729d7324

Trends :test_tube:

Image of Build Times

Steps errors 2

Expand to view the steps failures

Load a resource file from a shared library
  • Took 0 min 0 sec . View more details on here
  • Description: approval-list/elastic/ecs-logging-nodejs.yml
Error signal
  • Took 0 min 0 sec . View more details on here
  • Description: githubPrCheckApproved: The PR is not allowed to run in the CI yet. (Only users with write permissions can do so.)

Log output

Expand to view the last 100 lines of log output

[2021-08-25T17:34:06.805Z]  > git config core.sparsecheckout # timeout=10
[2021-08-25T17:34:06.810Z]  > git checkout -f ec077a79897bb44b03a3c1bb3695f1e9729d7324 # timeout=15
[2021-08-25T17:34:11.541Z] Commit message: "Fix TS import without esModuleInterop option"
[2021-08-25T17:34:11.541Z] First time build. Skipping changelog.
[2021-08-25T17:34:11.541Z] Cleaning workspace
[2021-08-25T17:34:11.655Z]  > git --version # timeout=10
[2021-08-25T17:34:11.659Z]  > git --version # 'git version 2.17.1'
[2021-08-25T17:34:11.672Z] fatal: bad object 78e5924a6e8b35eccae35ddfa32af978e6f3e658
[2021-08-25T17:34:11.544Z]  > git rev-parse --verify HEAD # timeout=10
[2021-08-25T17:34:11.553Z] Resetting working tree
[2021-08-25T17:34:11.554Z]  > git reset --hard # timeout=10
[2021-08-25T17:34:11.568Z]  > git clean -fdx # timeout=10
[2021-08-25T17:34:12.519Z] Masking supported pattern matches of $JOB_GCS_BUCKET or $NOTIFY_TO
[2021-08-25T17:34:12.604Z] Timeout set to expire in 1 hr 0 min
[2021-08-25T17:34:12.629Z] The timestamps step is unnecessary when timestamps are enabled for all Pipeline builds.
[2021-08-25T17:34:12.851Z] [INFO] Number of builds to be searched 10
[2021-08-25T17:34:12.988Z] [INFO] 'shallow' is forced to be disabled when running on PullRequests
[2021-08-25T17:34:13.012Z] Running in /var/lib/jenkins/workspace/ejs_ecs-logging-nodejs-mbp_PR-90/src/go.elastic.co/apm/ecs-logging-nodejs
[2021-08-25T17:34:13.051Z] [INFO] gitCheckout: Checkout SCM PR-90 with default customisation from the Item.
[2021-08-25T17:34:13.086Z] [INFO] Override default checkout
[2021-08-25T17:34:13.150Z] Sleeping for 10 sec
[2021-08-25T17:34:23.184Z] The recommended git tool is: NONE
[2021-08-25T17:34:23.442Z] using credential f6c7695a-671e-4f4f-a331-acdce44ff9ba
[2021-08-25T17:34:23.449Z] Wiping out workspace first.
[2021-08-25T17:34:23.462Z] Cloning the remote Git repository
[2021-08-25T17:34:23.462Z] Using shallow clone with depth 3
[2021-08-25T17:34:23.462Z] Avoid fetching tags
[2021-08-25T17:34:23.526Z] Cloning repository [email protected]:elastic/ecs-logging-nodejs.git
[2021-08-25T17:34:23.599Z]  > git init /var/lib/jenkins/workspace/ejs_ecs-logging-nodejs-mbp_PR-90/src/go.elastic.co/apm/ecs-logging-nodejs # timeout=10
[2021-08-25T17:34:23.605Z] Fetching upstream changes from [email protected]:elastic/ecs-logging-nodejs.git
[2021-08-25T17:34:23.606Z]  > git --version # timeout=10
[2021-08-25T17:34:23.612Z]  > git --version # 'git version 2.17.1'
[2021-08-25T17:34:23.613Z] using GIT_SSH to set credentials GitHub user @elasticmachine SSH key
[2021-08-25T17:34:23.617Z]  > git fetch --no-tags --progress -- [email protected]:elastic/ecs-logging-nodejs.git +refs/heads/*:refs/remotes/origin/* # timeout=15
[2021-08-25T17:34:24.298Z] Cleaning workspace
[2021-08-25T17:34:24.317Z] Using shallow fetch with depth 3
[2021-08-25T17:34:24.317Z] Pruning obsolete local branches
[2021-08-25T17:34:24.853Z] Merging remotes/origin/master commit 9bc98bbe24d3e86aedc648906a905760b5acc6b9 into PR head commit ec077a79897bb44b03a3c1bb3695f1e9729d7324
[2021-08-25T17:34:24.920Z] Merge succeeded, producing ec077a79897bb44b03a3c1bb3695f1e9729d7324
[2021-08-25T17:34:24.920Z] Checking out Revision ec077a79897bb44b03a3c1bb3695f1e9729d7324 (PR-90)
[2021-08-25T17:34:24.952Z] Commit message: "Fix TS import without esModuleInterop option"
[2021-08-25T17:34:24.952Z] Cleaning workspace
[2021-08-25T17:34:24.997Z]  > git --version # timeout=10
[2021-08-25T17:34:25.001Z]  > git --version # 'git version 2.17.1'
[2021-08-25T17:34:25.005Z] fatal: bad object 78e5924a6e8b35eccae35ddfa32af978e6f3e658
[2021-08-25T17:34:24.283Z]  > git config remote.origin.url [email protected]:elastic/ecs-logging-nodejs.git # timeout=10
[2021-08-25T17:34:24.287Z]  > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
[2021-08-25T17:34:24.294Z]  > git config remote.origin.url [email protected]:elastic/ecs-logging-nodejs.git # timeout=10
[2021-08-25T17:34:24.302Z]  > git rev-parse --verify HEAD # timeout=10
[2021-08-25T17:34:24.307Z] No valid HEAD. Skipping the resetting
[2021-08-25T17:34:24.307Z]  > git clean -fdx # timeout=10
[2021-08-25T17:34:24.320Z] Fetching upstream changes from [email protected]:elastic/ecs-logging-nodejs.git
[2021-08-25T17:34:24.320Z] using GIT_SSH to set credentials GitHub user @elasticmachine SSH key
[2021-08-25T17:34:24.323Z]  > git fetch --no-tags --progress --prune -- [email protected]:elastic/ecs-logging-nodejs.git +refs/pull/90/head:refs/remotes/origin/PR-90 +refs/heads/master:refs/remotes/origin/master # timeout=15
[2021-08-25T17:34:24.856Z]  > git config core.sparsecheckout # timeout=10
[2021-08-25T17:34:24.859Z]  > git checkout -f ec077a79897bb44b03a3c1bb3695f1e9729d7324 # timeout=15
[2021-08-25T17:34:24.882Z]  > git remote # timeout=10
[2021-08-25T17:34:24.886Z]  > git config --get remote.origin.url # timeout=10
[2021-08-25T17:34:24.898Z] using GIT_SSH to set credentials GitHub user @elasticmachine SSH key
[2021-08-25T17:34:24.901Z]  > git merge 9bc98bbe24d3e86aedc648906a905760b5acc6b9 # timeout=10
[2021-08-25T17:34:24.909Z]  > git rev-parse HEAD^{commit} # timeout=10
[2021-08-25T17:34:24.923Z]  > git config core.sparsecheckout # timeout=10
[2021-08-25T17:34:24.932Z]  > git checkout -f ec077a79897bb44b03a3c1bb3695f1e9729d7324 # timeout=15
[2021-08-25T17:34:24.955Z]  > git rev-parse --verify HEAD # timeout=10
[2021-08-25T17:34:24.958Z] Resetting working tree
[2021-08-25T17:34:24.959Z]  > git reset --hard # timeout=10
[2021-08-25T17:34:24.968Z]  > git clean -fdx # timeout=10
[2021-08-25T17:34:25.762Z] Masking supported pattern matches of $GIT_USERNAME or $GIT_PASSWORD
[2021-08-25T17:34:26.447Z] + git fetch https://****:****@github.com/elastic/ecs-logging-nodejs.git +refs/pull/*/head:refs/remotes/origin/pr/*
[2021-08-25T17:34:26.875Z] Running in /var/lib/jenkins/workspace/ejs_ecs-logging-nodejs-mbp_PR-90/src/go.elastic.co/apm/ecs-logging-nodejs/.git
[2021-08-25T17:34:26.980Z] Archiving artifacts
[2021-08-25T17:34:28.198Z] + git rev-parse HEAD
[2021-08-25T17:34:28.601Z] + git rev-parse HEAD
[2021-08-25T17:34:28.930Z] + git rev-parse origin/pr/90
[2021-08-25T17:34:28.983Z] [INFO] githubEnv: Found Git Build Cause: pr
[2021-08-25T17:34:29.202Z] Masking supported pattern matches of $GITHUB_TOKEN
[2021-08-25T17:34:30.206Z] [WARN] githubApiCall: The REST API call https://api.github.com/repos/elastic/ecs-logging-nodejs/pulls/90/reviews return 0 elements
[2021-08-25T17:34:30.268Z] [INFO] githubPrCheckApproved: Title: Fix TS import without esModuleInterop option - User: lundibundi - Author Association: FIRST_TIME_CONTRIBUTOR
[2021-08-25T17:34:30.603Z] ERROR: githubPrCheckApproved: The PR is not allowed to run in the CI yet
[2021-08-25T17:34:30.603Z] ERROR: githubPrCheckApproved: The PR is not allowed to run in the CI yet. (Only users with write permissions can do so.)
[2021-08-25T17:34:30.683Z] [INFO] Let's stop build #1. The PR is not allowed to run in the CI yet
[2021-08-25T17:34:30.709Z] Sleeping for 5 sec
[2021-08-25T17:34:31.752Z] Stage "Parallel" skipped due to earlier failure(s)
[2021-08-25T17:34:31.912Z] Stage "Test - Node.js v10" skipped due to earlier failure(s)
[2021-08-25T17:34:31.927Z] Stage "Test - Node.js v12" skipped due to earlier failure(s)
[2021-08-25T17:34:31.940Z] Stage "Test - Node.js v14" skipped due to earlier failure(s)
[2021-08-25T17:34:31.952Z] Stage "Test - Node.js v15" skipped due to earlier failure(s)
[2021-08-25T17:34:32.064Z] Failed in branch Test - Node.js v10
[2021-08-25T17:34:32.074Z] Failed in branch Test - Node.js v12
[2021-08-25T17:34:32.085Z] Failed in branch Test - Node.js v14
[2021-08-25T17:34:32.096Z] Failed in branch Test - Node.js v15
[2021-08-25T17:34:32.477Z] Running on Jenkins in /var/lib/jenkins/workspace/ejs_ecs-logging-nodejs-mbp_PR-90
[2021-08-25T17:34:32.700Z] [INFO] getVaultSecret: Getting secrets
[2021-08-25T17:34:32.756Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-08-25T17:34:33.651Z] + chmod 755 generate-build-data.sh
[2021-08-25T17:34:33.651Z] + ./generate-build-data.sh https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-nodejs/ecs-logging-nodejs-mbp/PR-90/ https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-nodejs/ecs-logging-nodejs-mbp/PR-90/runs/1 ABORTED 188140
[2021-08-25T17:34:33.651Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-nodejs/ecs-logging-nodejs-mbp/PR-90/runs/1/steps/?limit=10000 -o steps-info.json
[2021-08-25T17:34:33.651Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-nodejs/ecs-logging-nodejs-mbp/PR-90/runs/1/tests/?status=FAILED -o tests-errors.json
[2021-08-25T17:34:33.902Z] Retry 1/3 exited 22, retrying in 1 seconds...
[2021-08-25T17:34:34.813Z] Retry 2/3 exited 22, retrying in 2 seconds...

apmmachine avatar Aug 25 '21 17:08 apmmachine

@lundibundi Thanks for this. What do you think about my approach in https://github.com/elastic/ecs-logging-nodejs/pull/96 which moves to using export default ... rather than export =?

trentm avatar Aug 30 '21 22:08 trentm

@trentm Sorry for late response, I've tried your PR by manually changing index.d.ts like this:

export default createEcsPinoOptions;
export { createEcsPinoOptions }

And in the project with

// tsconfig.json
"allowSyntheticDefaultImports": true

And got for `escFormat({ convertErr: true }):

TS2349: This expression is not callable.
  Type 'typeof import("...omitted.../node_modules/@elastic/ecs-pino-format/index")' has no call signatures.
...
import * as escFormat from '@elastic/ecs-pino-format';
...
escFormat({ convertErr: true })

But:

escFormat.createEcsPinoOptions({ convertErr: true })

worked which I assume is an intended way.

So I'd be fine with either solution, thanks.

lundibundi avatar Sep 09 '21 11:09 lundibundi