Parcel: Third Party library import failed

Created on 21 Jan 2019  路  4Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

When I use parcel to bundle my project with react-model, It works on CodeSandBox, but crash on local (I test on my Linux node v8.x and macOS node v10.x)

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

package.json

{
  "name": "parcel-react-model-template",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "scripts": {
    "start": "parcel index.html --open",
    "build": "parcel build index.html"
  },
  "dependencies": {
    "react": "16.8.0-alpha.1",
    "react-dom": "16.8.0-alpha.1",
    "react-model": "2.0.11",
    "typescript": "3.2.4"
  },
  "devDependencies": {
    "@types/react": "16.7.20",
    "@types/react-dom": "16.0.11",
    "parcel-bundler": "^1.6.1"
  },
  "keywords": []
}

馃 Expected Behavior


npm start with no import error

馃槸 Current Behavior

Uncaught TypeError: react_model_1.Model is not a function
    at Object.parcelRequire.model/index.ts.react-model

馃拋 Possible Solution


ES6/esnext module support
Now I remove the module field in [email protected] package.json to solve the issue.

馃敠 Context


node_modules/react-model/package.json

// ...
"license": "MIT",
  "main": "./dist/react-model.js",
  "module": "./dist/react-model",
  "name": "react-model",
// ...

When I Change it to

"license": "MIT",
  "main": "./dist/react-model.js",
  "module": "./dist/react-model.js",
  "name": "react-model",

Parcel can work well, But the file ./dist/react-model is a valid ES module under webpack. And this solution will be broken under webpack. What's wrong, What should I do ?

馃捇 Code Sample


CodeSandBox

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | v1.6.1 / v1.11.0 |
| Node | v8.x / v10.x |
| npm/Yarn | -- |
| Operating System | Linux / macOS |

Bug 鉁栵笍 Non-Parcel bug

All 4 comments

Maybe smth wrong with react-module?

I can't reproduce this (anymore). react-model doesn't (and didn't? https://unpkg.com/[email protected]/package.json) have a module property in it's package.json.
Adding the line seems to make no difference. Are you still having issues?

I can't reproduce this (anymore). react-model doesn't (and didn't? https://unpkg.com/[email protected]/package.json) have a module property in it's package.json.
Adding the line seems to make no difference. Are you still having issues?

I remove the module field in [email protected] so you can't reproduce it.

You can reproduce this in [email protected]
the same as package.json above.

project's package.json

{
  "name": "parcel-react-model-template",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "scripts": {
    "start": "parcel index.html --open",
    "build": "parcel build index.html"
  },
  "dependencies": {
    "react": "16.8.0-alpha.1",
    "react-dom": "16.8.0-alpha.1",
    "react-model": "2.0.11",
    "typescript": "3.2.4"
  },
  "devDependencies": {
    "@types/react": "16.7.20",
    "@types/react-dom": "16.0.11",
    "parcel-bundler": "^1.6.1"
  },
  "keywords": []
}

react-model's package.json

// ...
"license": "MIT",
  "main": "./dist/react-model.js",
  "module": "./dist/react-model",
  "name": "react-model",
// ...

@ArrayZoneYour You can't have a javascript file without a file extension. Renaming dist/react-model to react-model.esm.js (and changing package.json) fixes it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mnn picture mnn  路  3Comments

philipodev picture philipodev  路  3Comments

dsky1990 picture dsky1990  路  3Comments

Niggler picture Niggler  路  3Comments

466023746 picture 466023746  路  3Comments