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

Fix running error by reverting import with type json #1422

Closed
wants to merge 2 commits into from

Conversation

ekohilas
Copy link
Contributor

When running the tool, the following error is returned:

npx --yes gitlab-ci-local@latest                                                                                                                                                 
file:///Users/username/.npm/_npx/3f18f2096def1b34/node_modules/gitlab-ci-local/src/index.js:13
import packageJson from "../package.json" with { type: "json" };
                                          ^^^^

SyntaxError: Unexpected token 'with'
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14)
    at async link (node:internal/modules/esm/module_job:68:21)

Node.js v18.18.2

Minimal .gitlab-ci.yml illustrating the issue

---
job:
  script:
    - echo "Heya"

Expected behavior
Tool to run

Host information
MacOs
gitlab-ci-local 4.55

Containerd binary
Are you using docker

Additional context
This seems related to #1331 and #1337

My installed typescript version is 5.6.3, so I don't think it's that.

Still trying to figure out why this doesn't work.

@ekohilas
Copy link
Contributor Author

Locally, if I compile with npm run esbuild and run ./bin/index.cjs it works fine.

But if I compile with npm run build and run node src/index.js I get the error.

@ANGkeith
Copy link
Collaborator

ANGkeith commented Nov 11, 2024

You can set NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules"

and that should fix the error you're seeing with some warnings


i am guessing you're trying to do some local dev..

i'll actually recommend using:

- npm run dev                          # if you're a fan of hot-reloading
- npm run dev -- --list-json           # if you want only want to test the `--list-json` option
- npx tsx src/index.ts --list-json     # no hot-reload

@ekohilas
Copy link
Contributor Author

You can set NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules"
the error should be gone

I'll give it a go

i am guessing you're trying to do some local dev..

No actually, I was using npx gitlab-ci-local@latest to run the project without directly installing it, I'm not sure what happens when I install it normally

@ekohilas
Copy link
Contributor Author

You can set NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules"
the error should be gone

I'll give it a go

If I run NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" npx gitlab-ci-local@latest, I get the same error.

@ekohilas
Copy link
Contributor Author

No actually, I was using npx gitlab-ci-local@latest to run the project without directly installing it, I'm not sure what happens when I install it normally

It still does fail.

@ANGkeith
Copy link
Collaborator

ANGkeith commented Nov 11, 2024

manage to replicate your issue via

FROM node:18.18 
# FROM node:18.20 # works for 18.20 and beyond

WORKDIR /app

RUN apt-get update && \
  apt-get install -y rsync git && \
  rm -rf /var/lib/apt/lists/*


RUN cat <<EOF > .gitlab-ci.yml
---
job:
  script:
  - echo "hello world" \
EOF

RUN  npx gitlab-ci-local@latest

@ANGkeith
Copy link
Collaborator

ANGkeith commented Nov 11, 2024

and to be honest, i am not exactly sure what value does the with { type: "json" }; adds

@ekohilas
Copy link
Contributor Author

and to be honest, i am not exactly sure what value does the with { type: "json" }; adds

After building, running node src/index.js fails with:


node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///Users/username/work/gitlab-ci-local/package.json" needs an import assertion of type "json"
    at new NodeError (node:internal/errors:405:5)
    at validateAssertions (node:internal/modules/esm/assert:95:15)
    at defaultLoad (node:internal/modules/esm/load:91:3)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at ESMLoader.load (node:internal/modules/esm/loader:603:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
    at new ModuleJob (node:internal/modules/esm/module_job:64:26)
    at #createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34)
    at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:21) {
  code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING'
}

@ANGkeith
Copy link
Collaborator

ANGkeith commented Nov 11, 2024

and to be honest, i am not exactly sure what value does the with { type: "json" }; adds

opps, i was'nt saying that it's not good.. was actually about to approve it

but yeah anyways, don't really have too much opinion on the way to import the json file... as long as it works and passes the integaration tests

@ekohilas
Copy link
Contributor Author

ekohilas commented Nov 11, 2024

And with the latest commit, it fails with

undefined:1
./schema.json
^

SyntaxError: Unexpected token . in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.<anonymous> (/Users/username/work/gitlab-ci-local/bin/index.cjs:157:7577)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.18.2

I suspect because ./schema.json doesn't exist when built together (and that I'm not sure how to fix)

No I'm just an idiot who forgot how to parse json...

@ANGkeith
Copy link
Collaborator

https://github.com/firecow/gitlab-ci-local/blame/master/README.md#L391

most effortless change would be update to node 18.20 + 😂

@ekohilas
Copy link
Contributor Author

I agree it's a good idea to update the required version.

On my end, that'll take some time, and I've managed to get the branch in a state where everything is passing.

I'd appreciate the acceptance of an interim solution for us.

@ekohilas
Copy link
Contributor Author

I can't re-open this PR, but I can make a new one if you can't either.

@ekohilas ekohilas mentioned this pull request Nov 11, 2024
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

Successfully merging this pull request may close these issues.

2 participants