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

Problems with ESM Import of "rdf-ext" in Github Action #249

Open
jannikreisberg opened this issue Mar 15, 2022 · 4 comments
Open

Problems with ESM Import of "rdf-ext" in Github Action #249

jannikreisberg opened this issue Mar 15, 2022 · 4 comments
Labels
question A question on how to use this action

Comments

@jannikreisberg
Copy link

jannikreisberg commented Mar 15, 2022

Describe the bug
It is not possible to import an npm package via ESM (package: rdf-ext).

I want to import the npm package rdf-ext, but as it is a ESM, I can not import it with require()

Therefore I need to use the import function, see here your documentation:
https://github.com/actions/github-script#use-esm-import

There it is said:
"To import an ESM file, you'll need to reference your script by an absolute path and ensure you have a package.json file with "type": "module" specified."

-> How should I have an absolute path to this package as I want to directly have it used without copying the package to my repo manually or so.

-> How can I achieve the changing of the package.json file? It is not good documentated how to find this and where to change it.

Look for my example repo: https://github.com/jannikreisberg/test-rdf-ext/blob/main/.github/workflows/main.yml

If possible, please just change the main.yml to a version how it will work, would be great!

Error information:

That's the error I got if I use the line:

const rdf = require('rdf-ext');

->

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/work/test-rdf-ext/test-rdf-ext/node_modules/rdf-ext/index.js from /home/runner/work/_actions/actions/github-script/v6/dist/index.js not supported. 
13Instead change the require of /home/runner/work/test-rdf-ext/test-rdf-ext/node_modules/rdf-ext/index.js in /home/runner/work/_actions/actions/github-script/v6/dist/index.js to a dynamic import() which is available in all CommonJS modules.

And if I update the line to the import line:

const rdf = import('rdf-ext');

That's the error I got if I use the line ->

Error: Unhandled error: SyntaxError: Cannot use import statement outside a module

Expected behavior
Sucessful import of rdf-ext package

Thanks a lot and Cheers from Hamburg!

@jannikreisberg jannikreisberg changed the title Problems with EM Import of "rdf-ext" Problems with ESM Import of "rdf-ext" Mar 15, 2022
@jannikreisberg jannikreisberg changed the title Problems with ESM Import of "rdf-ext" Problems with ESM Import of "rdf-ext" in Github Action Mar 16, 2022
@jannikreisberg
Copy link
Author

No one able to help?

@joshmgross
Copy link
Member

Are you able to import the file using the full path to where it's installed by npm install?

@joshmgross
Copy link
Member

I think you'll also want to change your package.json to include "type": "module"

https://github.com/jannikreisberg/test-rdf-ext/blob/main/package.json

@joshmgross joshmgross added the question A question on how to use this action label Mar 31, 2022
@ShaMan123
Copy link

+1

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

No branches or pull requests

3 participants