dmmulroy / create-melange-app

The fastest, friendliest, and most delightful way to get started with OCaml, ReasonML, and Melange, geared towards JavaScript and TypeScript developers
121 stars 20 forks source link

ERROR Failed attempting to build your project with Dune #91

Open bentxt opened 8 months ago

bentxt commented 8 months ago

npm create melange-app@latest

 ERROR

    Failed attempting to build your project with Dune
    The scaffolding process failed while running `opam exec -- dune build`.
    Dune is OCaml and ReasonML's build tool.
    Please try `cd`ing into the project directory created by
    `create-melange-app` and running the following commands:

    eval $(opam env)
    dune build
[...]
    `opam switch list`,
    `dune build`,
    `cat dune-project`, and `cat dune`

eval $(opam env)

dune build

ben@moonraker meli $ dune build
File "dune", line 32, characters 0-349:
32 | (rule
33 |   (alias webpack)
34 |    (targets (dir dist))
....
41 |               --entry ./output/src/App.mjs && cp ./public/index.html dist/index.html"))
42 |    (mode
43 |      (promote (until-clean))))
/bin/sh: ../../node_modules/.bin/webpack: No such file or directory

opam switch list

ben@moonraker meli 1 $ opam switch list
#   switch                                         compiler                    description
    /Users/ben/build/flow/flow                     ocaml-base-compiler.4.14.0  /Users/ben/build/flow/flow
    /Users/ben/hack/melange/melange-opam-template  ocaml-base-compiler.5.1.0   /Users/ben/hack/melange/melange-opam-template
->  /Users/ben/hack/melange/meli/meli              ocaml-base-compiler.5.1.1   /Users/ben/hack/melange/meli/meli
    /Users/ben/sources/nox/nox                     ocaml-base-compiler.5.0.0   /Users/ben/sources/nox/nox
    default                                        ocaml.5.1.1                 default

[NOTE] Current switch has been selected based on the current directory.
       The current global system switch is default.

dune build

ben@moonraker meli $ dune build
File "dune", line 32, characters 0-349:
32 | (rule
33 |   (alias webpack)
34 |    (targets (dir dist))
....
41 |               --entry ./output/src/App.mjs && cp ./public/index.html dist/index.html"))
42 |    (mode
43 |      (promote (until-clean))))
/bin/sh: ../../node_modules/.bin/webpack: No such file or directory

dune file

 $ perl -nle '/^;/ || print' dune

(dirs :standard \ node_modules)

(alias
  (name all)
  (deps
     (alias_rec webpack)))

(rule
  (alias webpack)
   (targets (dir dist))
   (deps
     (alias_rec meli)
     (:webpack ./webpack.config.js)
     (source_tree ./public))
   (action
    (system "../../node_modules/.bin/webpack --mode production \
              --entry ./output/src/App.mjs && cp ./public/index.html dist/index.html"))
   (mode
     (promote (until-clean))))

  (melange.emit
   (target output)
   (alias meli)
   (libraries app)
   (module_systems (es6 mjs)))

dune-project file

$ perl -nle '/^;/ || print' dune-project
(lang dune 3.14)

(using melange 0.1)

(using directory-targets 0.1)

(name meli)

(generate_opam_files true)

(source
 (github your-username/meli))

(authors "Your Name <your.email@gmail.com>")

(maintainers "Your Name <your.email@gmail.com>")

(license MIT)

(documentation https://github.com/your-username/meli)

(package
 (name meli)
 (synopsis "Enter a synopsis of your app here")
 (description "Enter a description of your app here")
 (allow_empty)
 (depends
  (dune (>= 3.14))
  (melange (>= 3.0.0-51))
  (ocaml (>= 5.1.1))
  opam-check-npm-deps
  ppx_deriving
  (reason (>= 3.11.0))
)
 (tags
  (reasonml, ocaml, melange)))
dmmulroy commented 8 months ago

By chance did you opt out of running npm install? Could you share the package.json that was generated?

irfanns commented 5 months ago

Hi, I got this issue too with both vite and webpack. Seems there's an issue with dune build getting to the node_modules/ subfolder in the project root, as the dune build seems to happen two folders upward of the created project?

Already ran npm install, npm i vite (for the vite project) and also npm i webpack (for the webpack project)

Thank you!

-- hi, after debugging locally, I think the problem was with opam switches. I have set the global opam switch to a top folder location and it seemed to have broke dune build. After deleting all local opam switches and trying again, it works now. Thanks!