Parcel: [2.0] "Cannot find module 'x' from 'y'"

Created on 17 Oct 2019  ยท  5Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

I tried running Parcel 2 alpha in my project to see how it goes, and I was presented with an error "Cannot find module...".

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

// .babelrc
{
  "presets": [
    ["@babel/preset-env", {
      "modules": false,
      "useBuiltIns": "usage",
      "corejs": 3
    }],
    "@babel/preset-react"
  ],
  "plugins": [
    "@babel/plugin-proposal-export-default-from",
    "@babel/plugin-proposal-optional-chaining"
  ],
}

CLI command:

    "start": "parcel src/index.html --cache-dir ./.cache/dev",

๐Ÿค” Expected Behavior

Parcel to successfully resolve paths and build the application like in 1.x

๐Ÿ˜ฏ Current Behavior

Server running at http://localhost:1234
๐Ÿšจ Cannot find module '../components/pages/form/step_context' from '/Users/wojciech.maj/P
rojekty/cfola/src/hooks'
    at ResolverRunner.resolve (/Users/wojciech.maj/Projekty/cfola/node_modules/@parcel/co
re/lib/ResolverRunner.js:71:15)
    at async RequestGraph.resolvePath (/Users/wojciech.maj/Projekty/cfola/node_modules/@p
arcel/core/lib/RequestGraph.js:400:24)
    at async PromiseQueue._runFn (/Users/wojciech.maj/Projekty/cfola/node_modules/@parcel
/utils/lib/PromiseQueue.js:94:7)
    at async PromiseQueue._next (/Users/wojciech.maj/Projekty/cfola/node_modules/@parcel/
utils/lib/PromiseQueue.js:81:5)

And below the spinner is just stuck, rotating on:

โ  Building checkmark.svg...

Obviously, this path (/Users/wojciech.maj/P rojekty/cfola/src/components/pages/form/step_context) is very much there so I don't know why this problem occurred.

๐Ÿ’ Possible Solution

๐Ÿ”ฆ Context

๐Ÿ’ป Code Sample

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-alpha.2.1
| Node | 12.4.0
| npm/Yarn | 1.19.1
| Operating System | MacOS Catalina

Bug Confirmed Bug โœจ Parcel 2

All 5 comments

Could you share a code sample or reproduction repo?

Ha! I stripped my repo down to several files and I figured it out.

So I ended up with this simple tree of dependencies:

index.html
  index.jsx
    useHello.js
      hello.jsx

and ended up with the same error:

  Cannot find module './hello' from '/Users/wojciech.maj/Projekty/cfola/src'

Turns out that while html and jsx files are perfectly able to resolve jsx files, js files cannot. When I changed hello.jsx into hello.jsit started building.

...until the next place in which I had the same situation.

Just ran into this as well ๐Ÿ™ˆ

The reason is that jsx is missing in this array:
https://github.com/parcel-bundler/parcel/blob/96c25fa775395f005d6b483020d6b522d29d3dfe/packages/resolvers/default/src/DefaultResolver.js#L33

But the goal is to get rid of this hardcoded list anyway....

Can we get it on this hardcoded list just for now, for me to be able to continue testing Parcel 2 Alpha?

Was this page helpful?
0 / 5 - 0 ratings