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

ncc is unable to import third party modules via "import". Cannot read properties of undefined #1124

Closed
mavendonovanhubbard opened this issue Oct 14, 2023 · 1 comment

Comments

@mavendonovanhubbard
Copy link

mavendonovanhubbard commented Oct 14, 2023

I have the following typescript code:

import core from "@actions/core";
console.log(core.getInput("foo"));

Building it with ncc build src/main.ts -o dist and executing it returns

console.log(core_1.default.getInput("foo"));
                           ^

TypeError: Cannot read properties of undefined (reading 'getInput')

I've found that by converting the import statement to a require statement, const core = require("@actions/core"); the code executes successfully.

I've also found that core, first-party node modules like fs can be imported via an import statement as well as my local code while any third-party modules I tried have the above error.

I'm running ncc version 0.38.0
Here is my tsconfig.json file:

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "./dist/",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

edit: corrected the ncc version number.

@mavendonovanhubbard
Copy link
Author

The solution was to import the library with a *.

import * as core from "@actions/core"

This is described here: https://stackoverflow.com/questions/65227202/github-actions-how-to-work-with-typescript and is an example in the official documentation here. https://github.com/actions/typescript-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant