fermyon / spin-js-sdk

https://developer.fermyon.com/spin/javascript-components
Apache License 2.0
49 stars 17 forks source link

yargs cannot be found #232

Closed bacongobbler closed 2 months ago

bacongobbler commented 3 months ago

With @fermyon/spin-sdk@2.0.0-alpha.0, if I run npx j2w, I see the following:

><> npx j2w
node:internal/modules/esm/resolve:854
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'yargs' imported from /home/bacongobbler/code/github.com/fermyon/spinkube-dashboard/node_modules/@fermyon/spin-sdk/bin/j2w.mjs
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.12.2

This is resolved if I run npm install -D yargs.

><> npm install -D yargs

added 13 packages, and audited 411 packages in 706ms

148 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
><> npx j2w
Options:
      --help                Show help                                  [boolean]
      --version             Show version number                        [boolean]
  -i, --input               Path to the input file                    [required]
  -d, --wit-path            Path to wit file or folder                [required]
  -o, --output              Path to the output file  [default: "component.wasm"]
      --trigger-type, ---n  Spin trigger to target
                                               [required] [choices: "spin-http"]

Missing required arguments: input, wit-path, trigger-type

I'm wondering if yargs should be added as a dependency of this project rather than a devDependency. What do you think?

https://github.com/fermyon/spin-js-sdk/blob/feat/sdk-v2/package.json#L19

karthik2804 commented 3 months ago

I am not able to reproduce this locally. The template does specify a devDependency on yargs https://github.com/fermyon/spin-js-sdk/blob/99a38550a608c768f4d0bdb413acad102bb35fb0/templates/http-ts/content/package.json#L20

But I think you are correct in suggesting that it needs to be a dependency and not a devDependency. I think we can remove yargs and componentize-js from the dev dependency list on the template once those 2 are added as prod dependencies to the SDK package.

bacongobbler commented 3 months ago

It works if you use the ts template, but it doesn't work if you try to install this package in a standalone app (choose your own adventure style 😄).

Here is how I was able to reproduce this locally:

><> mkdir myapp
><> cd myapp
><> npm init
><> npm install @fermyon/spin-sdk
><> npx j2w
node:internal/modules/esm/resolve:854
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@bytecodealliance/componentize-js' imported from /home/bacongobbler/code/github.com/bacongobbler/myapp/node_modules/@fermyon/spin-sdk/bin/j2w.mjs
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.12.2
bacongobbler commented 3 months ago

Fix for ^^:

><> npm install -D @bytecodealliance/componentize-js
><> npm install -D yargs
karthik2804 commented 3 months ago

Ah! We should add both those packages as prod dependencies on the SDK package. That should fix it.

bacongobbler commented 2 months ago

This works on the latest release. Closing.