docz: v1.0.0-rc.* Compiled with errors: Module parse failed: Unexpected token

Bug Report

Describe the bug

When I try to run docz dev I get multiple errors regarding an appropriate loader

✖ Docz
  Compiled with some errors in 29.12s



 ERROR  Failed to compile with 3 errors              12:00:39 PM

 error  in ./node_modules/docz/dist/index.esm.js

Module parse failed: Unexpected token (15:38)
You may need an appropriate loader to handle this file type.
| import { MDXProvider } from '@mdx-js/tag';
|
> const BasePlayground = loadable(() => import('./chunk.esm2.js'));
| const Playground = props => typeof window !== 'undefined' ? (createElement(Suspense, { fallback: null },
|     createElement(BasePlayground, Object.assign({}, props)))) : null;

 @ ./.docz/app/root.jsx 9:0-59 17:2-15 20:19-23 27:25-31
 @ ./.docz/app/index.jsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./.docz/app/index.jsx

 error  in ./node_modules/docz-theme-default/dist/index.esm.js

Module parse failed: Unexpected token (245:30)
You may need an appropriate loader to handle this file type.
| `;
|
> const CodeMirror = lazy(() => import('./chunk.esm2.js'));
| const getLanguage = (children) => {
|     const defaultLanguage = 'jsx';

 @ ./.docz/app/root.jsx 11:0-39 18:29-34
 @ ./.docz/app/index.jsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./.docz/app/index.jsx

 error  in ./.docz/app/imports.js

Module parse failed: Unexpected token (8:11)
You may need an appropriate loader to handle this file type.
| export var imports = {
|   'src/index.mdx': function srcIndexMdx() {
>     return import(
|     /* webpackPrefetch: true, webpackChunkName: "src-index" */
|     'src/index.mdx');

 @ ./.docz/app/root.jsx 12:0-36 28:13-20
 @ ./.docz/app/index.jsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./.docz/app/index.jsx

Environment

  • node v10.15.1
  • npm v6.8.0
  • react v16.8.4
  • npm ls webpack ├─┬ docz@1.0.0-rc.3 │ └─┬ docz-core@1.0.0-rc.3 │ └── webpack@4.29.6 └─┬ react-scripts@2.1.8 └── webpack@4.28.3

Additional context/Screenshots

Screenshot 2019-03-22 at 12 03 25

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 12
  • Comments: 35 (6 by maintainers)

Most upvoted comments

Also instead of installing webpack@4.28.2, you can specify it in resolutions in package.json

"resolutions": {
    "docz/**/webpack": "4.28.4"
}

Switching back to Storybook… such a waste of time.

No need to add those comments, the maintainer is doing a great job and does not deserve comments like that.

@pedronauck why this is closed?

I’m use CRA and installed docz@1.2.0, but after run the script there error ocurred:

Module parse failed: Unexpected token (23:38)
You may need an appropriate loader to handle this file type.
| import { MDXProvider } from '@mdx-js/react';
| 
> const BasePlayground = loadable(() => import('./Playground.esm.js'));
| const Playground = props => typeof window !== 'undefined' ? createElement(Suspense, {
|   fallback: null

This issue should not be closed.

I’ll pin acorn to the right dependency version on docz, but if you want some solution, try this:

  • Keep docz dependencies like that:
"devDependencies": {
  "docz": "1.0.0-rc.7",
  "docz-core": "1.0.0-rc.7",
  "docz-theme-default": "1.0.0-rc.7",
},

It’s important to keep absolute version without ^.

  • Then, add acorn@6.0.5 as a devDependency as well:
$ npm add acorn@6.0.5 --save-dev
  • Finally, make a clean install of your packages
$ rm -rf node_modules package-lock.json && npm install

This could work 👍

Still broken for me as well, reverted back to version 0.13.7 for now.

@pedronauck But #596 doesn’t show the same error and the solution is not the same

Having the same issue. Though it was similar to #596, but I couldn’t fix it by downgrading webpack

I’ve tried the solutions above, but no one works, still not solved this problem. Anyone have a perfect solution? help me… bug

TLDR: Try webpack 4.31.0

I was facing this issue with 1.2.0. It took me an entire day, but upgrading all of my babel-related and webpack packages fixed it for me.

I tried pretty much everything in this thread, related threads, and Webpack issues and none of them worked.

After playing around with different combinations of package versions, I think the one that fixed it for me was upgrading webpack to 4.31.0.

Also instead of installing webpack@4.28.2, you can specify it in resolutions in package.json

"resolutions": {
    "docz/**/webpack": "4.28.4"
}

apparently this does not work when using workspaces

I’ll close this issue in order do #596

Digging into this, I saw that has a problem related to the way that npm solves dependencies, you can see more details about this here: https://github.com/webpack/webpack/issues/8656

I’ll try to find some solution and release in the next version.

For me, use yarn solves the problem, but it’s a temporal solution because I need to use npm.

@sanohin Adding above resolution and clean yarn install after that works for me. Thanks

Downgrading webpack or setting acorn to 6.0.5 didn’t help

❯ yarn why webpack
yarn why v1.15.2
[1/4] 🤔  Why do we have the module "webpack"...?
[2/4] 🚚  Initialising dependency graph...
warning Resolution field "webpack@4.28.4" is incompatible with requested version "webpack@4.28.3"
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "webpack@4.28.4"
info Reasons this module exists
   - "react-scripts" depends on it
   - Hoisted from "react-scripts#webpack"
   - Hoisted from "docz#docz-core#webpack"
info Disk size without dependencies: "2.34MB"
info Disk size with unique dependencies: "7.26MB"
info Disk size with transitive dependencies: "27.41MB"
info Number of shared dependencies: 118
✨  Done in 1.27s.

Do you have an ideas what else can be an issue?

Cleaning .docz, yarn.lock, package-lock.json, node_modules between attempts:

👍 Works

npm install npm run docz:dev

👎 Fails

yarn install yarn run docz:dev

Solution

yarn install yarn add -D webpack@4.28.4 yarn run docz:dev

Thanks for your help, @pedronauck 👍 I know answering questions like this one aren’t fun, but I do really, really appreciate your time ❤️

Did you try to downgrade webpack @dannyrb?

Unfortunately I’m still getting the issue with yarn and a clean project:

yarn
yarn add docz@next docz-theme-default@next --dev
add the optional scripts to package.json
yarn docz:dev

Still getting the same error.