Parcel: 馃悰 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Created on 21 Dec 2017  路  6Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

馃帥 Configuration (.babelrc, package.json, cli command)

.babelrc

{
  "presets": [
    ["env", {
      "targets": {
        "browsers": "last 2 versions"
      }
    }],
    "react"
  ],
  "plugins": [
    "transform-react-jsx",
    "transform-object-rest-spread",
    "transform-class-properties",
    "transform-es2015-modules-commonjs"
  ],
  "env": {
    "test": {
      "plugins": [
        "transform-es2015-modules-commonjs"
      ]
    }
  }
}

package.json

  "scripts": {
    "start": "parcel ./src/index.html -d ./demo -o",
    "build": "parcel ./src/index.js"
  },
  "dependencies": {
    "currency.js": "^1.0.1",
    "prop-types": "^15.6.0",
    "react": "^16.2.0"
  },
  "devDependencies": {
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "react-dom": "^16.2.0"
  }

馃槸 Current Behavior


Terminal:

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Browser console:

Uncaught Error: Cannot find module "."
    at webpackMissingModule (index.js:60)
    at ../react-currency-input/dist/index.js.require.14 (index.js:60)

馃拋 Possible Solution

I got nothing

馃敠 Context


I wrote a small react component and tried publishing it to our npm org and then Import it in another project.

It runs just fine with parcel, problems only appear when trying to import it on other applications. (the other app is running on create-react-app).

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.2.1
| Node | 8.6.0 (nvm)
| npm/Yarn | 5.3.0 (npm) / 1.2.1 (yarn)
| Operating System | Mac OSX El Capitan

Most helpful comment

I have exactly the same problem, I don't see an issue of this in CRA. @gugiserman did you find a solution?

All 6 comments

hmm this looks like a webpack issue? looks like it is failing in webpackMissingModule? how is this issue related to parcel?

@devongovett I just tested on another host app but this time i wrote the webpack config myself instead of using create-react-app and it works just fine.

Yeah, I think I should move this issue to CRA's repo maybe. Sorry mate

how to use parcel bundle js

i tell a joke, happy and so silly to me

I have exactly the same problem, I don't see an issue of this in CRA. @gugiserman did you find a solution?

I have the exact same problem!
@gugiserman were you able to fix it.

I guess I need to write some other build file for parcel, because now just writing parcel build ./src/index.js gives me the error above.

The only config I have is .babelrc:

{
  "presets": ["env"],
  "plugins": ["babel-plugin-transform-object-rest-spread"]
}

Do I need to build every file that gets imported into my src/index.js?

Would much appreciate any help!

@nardeas @mesqueeb nope, sorry

We eventually moved the project from CRA to a custom setup with webpack. I still have no idea how to fix this. 馃槥

Was this page helpful?
0 / 5 - 0 ratings