cooklang / cookcli

Command line program which provides a suite of tools to create shopping lists and maintain recipes.
https://cooklang.org
MIT License
781 stars 38 forks source link

Unable to build from source #83

Closed zerolatnc closed 1 year ago

zerolatnc commented 1 year ago

I tried to build from source on Arch Linux using the instructions provided in the README, but got this error:

> svelte-app@1.0.0 build
> rollup -c

[!] RollupError: Node tried to load your configuration file as CommonJS even 
though it is likely an ES module. To resolve this, change the extension of yo
ur configuration to ".mjs", set "type": "module" in your package.json file or
 pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
https://rollupjs.org/command-line-interface/#bundleconfigascjs
/home/user/custom-pkgs/cookcli-git/src/cookcli-0.4.0/ui/rollup.
config.js:1
import svelte from 'rollup-plugin-svelte';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

Then, as suggested in the output, I changed the filename of rollup.config.js to rollup.config.mjs, which resulted in this error:

> svelte-app@1.0.0 build
> rollup -c

[!] Error: Cannot find package 'rollup-plugin-svelte' imported from /home/user/custom-pkgs/cookcli-git/src/cookcli-0.4.0/ui/rollup.config.mj
s
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'rollup-plugin-svelte' impo
rted from /home/user/custom-pkgs/cookcli-git/src/cookcli-0.4.0/
ui/rollup.config.mjs
    at packageResolve (node:internal/modules/esm/resolve:844:9)
    at moduleResolve (node:internal/modules/esm/resolve:901:20)
    at defaultResolve (node:internal/modules/esm/resolve:1121:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36)

I am trying to build on Arch Linux using makepkg. I doubt that it has any effect on the behavior observed, but here is the PKGBUILD for completeness:

pkgname='cookcli-git'
_pkgname="${pkgname%-git}"
arch=('x86_64')
pkgver=0.4.0
pkgrel=1
pkgdesc='CookCLI is provided as a command-line tool to make Cook recipe management easier, and enable automation and scripting workflows for the CookLang ecosystem. Build from source.'
provides=("${_pkgname}")
conflicts=("${_pkgname}" "${_pkgname}-bin")
url='https://github.com/cooklang/cookcli'
license=('MIT')
makedepends=('rust' 'npm' 'rollup')

source=("cookcli_${pkgver}.tar.gz::https://github.com/cooklang/CookCLI/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('b66b7256074e85dee717855ffb149afde66591c14c2da47229a27b8c2fce222d')

build() {
    cd "${srcdir}/cookcli-${pkgver}"
    cd ui && npm run build
    cd ../src
    cargo build --release
}

I am not familiar with the Javascript ecosystem and I did not want to try this outside of makepkg to avoid npm downloading packages on to my host, so this is where I stopped.

Can someone please help me with this? :)

dubadub commented 1 year ago

I think the issue is that the build instructions missing npm install before npm build. Could you please try that? I updated README too for full set of commands.

zerolatnc commented 1 year ago

Yep, that fixed it. Thank you! :)

dubadub commented 1 year ago

Great! I think we can close the issue then.