bhauman / figwheel-main

Figwheel Main provides tooling for developing ClojureScript applications
https://figwheel.org
Eclipse Public License 1.0
640 stars 93 forks source link

Cannot find module '@cljs-oss/module-deps' building tests #271

Open paulbutcher opened 4 years ago

paulbutcher commented 4 years ago

If I create a new project with lein new figwheel-main then lein fig:test fails consistently with Error: Cannot find module '@cljs-oss/module-deps'.

This might be related to #21, which I note has a comment saying that it's cropped up again, but the behaviour I'm seeing is not intermittent: lein fig:build and lein fig:min work consistently, but lein fig:test fails every time.

paulbutcher commented 4 years ago

So I've done some more digging, and this problem only happens if I use both +npm-bundle and --reagent when generating the project. But it does happen completely reliably if I do that (see below):

paulbutcher@Pauls-16in-MBP Projects % lein new figwheel-main testing -- +npm-bundle --reagent
Generating fresh figwheel-main project.
  To get started:
  -->  Change into the 'testing' directory
  -->  IMPORTANT: run 'npm install'
  -->  Start build with 'lein fig:build'

paulbutcher@Pauls-16in-MBP Projects % cd testing
paulbutcher@Pauls-16in-MBP testing % npm install
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.

> fsevents@1.2.13 install /Users/paulbutcher/Projects/testing/node_modules/watchpack-chokidar2/node_modules/fsevents
> node install.js

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"14.14.0","npm":"6.14.8"})
npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0
npm WARN testing No repository field.
npm WARN testing No license field.

added 405 packages from 230 contributors and audited 405 packages in 8.033s

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

found 0 vulnerabilities

paulbutcher@Pauls-16in-MBP testing % lein fig:test                                          
2020-11-08 00:29:00.383:INFO::main: Logging initialized @3146ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Validating figwheel-main.edn
[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build test to "resources/public/cljs-out/test-main.js"
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '@cljs-oss/module-deps'
Require stack:
- /Users/paulbutcher/Projects/testing/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:132:18)
    at Object.runInThisContext (vm.js:309:38)
    at internal/process/execution.js:77:19
    at [eval]-wrapper:6:22
    at evalScript (internal/process/execution.js:76:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/paulbutcher/Projects/testing/[eval]' ]
}

[Figwheel] Successfully compiled build test to "resources/public/cljs-out/test-main.js" in 6.083 seconds.
Opening URL http://localhost:9500/test.html
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '@cljs-oss/module-deps'
Require stack:
- /Users/paulbutcher/Projects/testing/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:132:18)
    at Object.runInThisContext (vm.js:309:38)
    at internal/process/execution.js:77:19
    at [eval]-wrapper:6:22
    at evalScript (internal/process/execution.js:76:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/paulbutcher/Projects/testing/[eval]' ]
}
paulbutcher commented 4 years ago

For reference, I can "fix" this by adding "@cljs-oss/module-deps": "1.1.1" to devDependencies in package.json, but I'm not sure whether this really is a fix, or whether I'm just papering over the cracks?

neilyio commented 4 years ago

This is also happening for me, but when I npm install -D @cljs-oss/module-deps I get another error:

9:45:30 PM: [eval]:67
9:45:30 PM:         new enhancedResolve.NodeJsInputFileSystem(),
9:45:30 PM:         ^
9:45:30 PM: TypeError: enhancedResolve.NodeJsInputFileSystem is not a constructor
9:45:30 PM:     at [eval]:67:9
9:45:30 PM:     at Script.runInThisContext (vm.js:120:20)
9:45:30 PM:     at Object.runInThisContext (vm.js:311:38)
9:45:30 PM:     at Object.<anonymous> ([eval]-wrapper:10:26)
9:45:30 PM:     at Module._compile (internal/modules/cjs/loader.js:1138:30)
9:45:30 PM:     at evalScript (internal/process/execution.js:94:25)
9:45:30 PM:     at internal/main/eval_string.js:23:3

Error: Cannot find module '@cljs-oss/module-deps' is only happening for me with :optimizations :advanced. :optimizations :simple works fine.

warrenronsiek commented 3 years ago

Same issue, but it happens only when I try to :require an npm library. Adding @cljs-oss/module-deps to package.json solve it.

waldeinburg commented 3 years ago

I had kind of the same issue as @neilyio (it happened at all :optimizations settings). Removing node_modules and package-lock.json (maybe the latter wasn't necessary) and running npm install again fixed it.

volodymyrpavliuk commented 3 years ago

@waldeinburg I believe there are 2 issues:

I tested yarn instead of npm, and the first scenario works well - there is no need to remove node_modules / yarn.lock when adding a dependency from CLI using yarn add --dev @cljs-oss/module-deps

mjarus007 commented 2 years ago

Hi I'm getting the same error that @neilyio got but none of the proposed solutions work for me.

bhauman commented 2 years ago

You should never have to install @cljs-oss/module-deps. I'm looking at this now.

bhauman commented 2 years ago

The answer to this is that the template was never configured to set up testing for this combination of options.

To fix this in your projects:

To test.cljs.edn add :auto-bundle :webpack right next to :open-url.

In resources/public/test.html change the cljs-out/test-main.js to cljs-out/test/main_bundle.js

Sorry this was missed.

mjarus007 commented 2 years ago

Thanks for the fix

jschmuec commented 2 years ago

I see the same error when following the tutorial. I assume it is because I am using the "cruel" build config.