github-script icon indicating copy to clipboard operation
github-script copied to clipboard

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

Open jannikreisberg opened this issue 3 years ago • 4 comments

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 avatar Mar 15 '22 16:03 jannikreisberg

No one able to help?

jannikreisberg avatar Mar 31 '22 10:03 jannikreisberg

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

joshmgross avatar Mar 31 '22 21:03 joshmgross

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 avatar Mar 31 '22 21:03 joshmgross

+1

ShaMan123 avatar Sep 27 '22 16:09 ShaMan123