Docz: Error: Cannot find module 'react-docgen/dist/babylon'

Created on 27 Mar 2019  ·  33Comments  ·  Source: doczjs/docz

Bug Report

Describe the bug

Update to docz 1.0.0-rc.3
when run docz dev,an error has occurred.

Error: Cannot find module 'react-docgen/dist/babylon'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/ronghang/work/react-components/node_modules/react-docgen-external-proptypes-handler/index.js:15:13)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/ronghang/work/react-components/node_modules/docz/node_modules/docz-core/dist/index.js:57:48)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)

A clear and concise description of what the bug is.

I check the react-docgen-external-proptypes-handler source code,i found it uses a file that does not exist in try catch.

'react-docgen/dist/babylon' does not exist in the react-docgen-external-proptypes-handler.

try {
  const buildParser = require('react-docgen/dist/babelParser').default
  babylon = buildParser()
} catch (e) {
  babylon = require('react-docgen/dist/babylon').default
}

Most helpful comment

this issue still exists for me @^1.2.0 so not sure why this is closed

All 33 comments

Yeah, but we don't have this handler anymore inside the docz-core package, try to re-install your node modules and check if the version of docz-core is the same of the docz.

Yeah, but we don't have this handler anymore inside the docz-core package, try to re-install your node modules and check if the version of docz-core is the same of the docz.

https://github.com/pedronauck/docz/blob/master/core/docz-core/package.json
sure?

This is the dependencies of newest [email protected]

image

I'm getting the same error, have you some tips about how to fix it?

I'm getting the same error, have you some tips about how to fix it?

Not yet. Unless the latest docz-core package don't depend this handler anymore.

The only way I found is downgrading to rc.2 with fixing all transitive dependencies with yarn:

// package.json
  "resolutions": {
    "babel-plugin-export-metadata": "1.0.0-rc.2",
    "docz": "1.0.0-rc.2",
    "docz-core": "1.0.0-rc.2",
    "docz-plugin-css": "0.11.0",
    "docz-theme-default": "1.0.0-rc.2",
    "docz-utils": "1.0.0-rc.2",
    "load-cfg": "1.0.0-rc.2",
    "react-docgen-actual-name-handler": "1.0.0-rc.2"
  }

Then deleting usage of react-docgen-external-proptypes-handler with patch-package (works only if you use docz with typescript option):

diff --git a/node_modules/docz-core/dist/index.js b/node_modules/docz-core/dist/index.js
index 4fa1011..cac9e07 100644
--- a/node_modules/docz-core/dist/index.js
+++ b/node_modules/docz-core/dist/index.js
@@ -54,10 +54,7 @@ var evalSourceMapMiddleware = _interopDefault(require('react-dev-utils/evalSourc
 var ignoredFiles = _interopDefault(require('react-dev-utils/ignoredFiles'));
 var chokidar = _interopDefault(require('chokidar'));
 var equal = _interopDefault(require('fast-deep-equal'));
-var externalProptypesHandler = _interopDefault(require('react-docgen-external-proptypes-handler'));
-var actualNameHandler = _interopDefault(require('react-docgen-actual-name-handler'));
 var reactDocgenTs = _interopDefault(require('react-docgen-typescript'));
-var reactDocgen = _interopDefault(require('react-docgen'));
 var ts$1 = _interopDefault(require('typescript'));
 var get = _interopDefault(require('lodash/get'));

@@ -1398,36 +1395,12 @@ const tsParser = async (filepath, config, tsconfig, program) => {
         return null;
     }
 };
-const jsParser = async (filepath, config) => {
-    const resolver = config.docgenConfig.resolver ||
-        reactDocgen.resolver.findAllExportedComponentDefinitions;
-    const handlers = reactDocgen.defaultHandlers.concat([
-        externalProptypesHandler(filepath),
-        // importedProptypesHandler(filepath),
-        actualNameHandler,
-    ]);
-    return new Promise(resolve => {
-        try {
-            const code = fs.readFileSync(filepath, 'utf-8');
-            const data = reactDocgen.parse(code, resolver, handlers);
-            const fullpath = fileFullPath(filepath);
-            resolve({ [fullpath]: data });
-        }
-        catch (err) {
-            if (config.debug)
-                throwError(err);
-            resolve(null);
-        }
-    });
-};
 const docgen = async (files, config) => {
     const ts = config.typescript;
     const program = ts ? tsProgram(files) : null;
     const tsconfig = await findup('tsconfig.json', { cwd: root });
     const docs = await Promise.all(files.map(async (filepath) => {
-        return ts
-            ? tsParser(filepath, config, tsconfig, program)
-            : jsParser(filepath, config);
+        return tsParser(filepath, config, tsconfig, program);
     }));
     return docs.reduce((obj, doc) => (doc ? Object.assign({}, obj, doc) : obj), {});
 };

Downgrade was needed since routing is completely broken in rc.7

This should be fixed in the newest 1.0.0-rc.8, could you reinstall you dependencies and test?

@pedronauck

I started a new docz project and installed [email protected] and [email protected]. It worked great. But it still has this dependency react-docgen-external-proptypes-handler

yarn.lock

[email protected]:
  version "1.0.0-rc.8"
  resolved "https://registry.yarnpkg.com/docz-core/-/docz-core-1.0.0-rc.8.tgz#c9e1d47f273367bdf3444138cecad21fced9f33a"
  integrity sha512-SOJhyFj0VN6/yf7rEUkkO3yt7hldzZ4YFy8V0XOzlklM0NXNLvNFwA1GewVP5JGb66jN2MmC/rAgWvqGTUC9BQ==
  dependencies:
    "@babel/core" "7.4.3"
    "@babel/polyfill" "7.4.3"
    "@babel/runtime" "^7.4.3"
    "@mdx-js/loader" "^0.20.3"
    "@sindresorhus/slugify" "^0.9.0"
    "@svgr/webpack" "^4.1.0"
    acorn "6.0.5"
    babel-loader "^8.0.5"
    babel-plugin-export-metadata "1.0.0-rc.8"
    babel-plugin-named-asset-import "^0.3.1"
    babel-preset-react-app "^7.0.2"
    cache-loader "^2.0.1"
    chalk "^2.4.2"
    chokidar "^2.1.5"
    common-tags "^1.8.0"
    detect-port "^1.3.0"
    docz-utils "1.0.0-rc.8"
    dotenv "^7.0.0"
    env-dot-prop "^2.0.1"
    express "^4.16.4"
    fast-deep-equal "^2.0.1"
    fast-glob "^2.2.6"
    file-loader "^3.0.1"
    find-up "^3.0.0"
    friendly-errors-webpack-plugin "^1.7.0"
    fs-extra "^7.0.1"
    get-pkg-repo "^4.1.0"
    html-minifier "^4.0.0"
    humanize-string "^2.1.0"
    load-cfg "1.0.0-rc.8"
    lodash "^4.17.11"
    mini-html-webpack-plugin "^0.2.3"
    p-reduce "^2.1.0"
    react-dev-utils "^8.0.0"
    react-docgen "^4.1.0"
    react-docgen-actual-name-handler "1.0.0-rc.8"
    react-docgen-external-proptypes-handler "^1.0.2" // HERE

However, for my old docz project, I tried to install the newest 1.0.0-rc.8, it still reports same error: Error: Cannot find module 'react-docgen/dist/babylon'. That handler dependency is also present

I wonder if the handler is not the only source of the problem

On your old docz project, try to reinstall your node_modules and yarn.lock, did you try it?

@pedronauck yes, I did remove node_modules and yarn.lock

@pedronauck the problem is that you use ^ for rc dependencies. It leads that it always install latest rc no matter which version was requested. The only to fix it is yarn and its resolution field in package.json

@pedronauck the [email protected] still rely on the react-docgen-external-proptypes-handler "^1.0.2" in the package.json. Try to remove it.

~1.0.1~ 1.0.3 still has this issue

This is not an issue with this library. The error you are getting is getting squashed by this.
https://github.com/siddharthkp/react-docgen-external-proptypes-handler/blob/master/index.js#L11

try {
  const buildParser = require('react-docgen/dist/babelParser').default
  babylon = buildParser()
} catch (e) {
  babylon = require('react-docgen/dist/babylon').default
}

This try catch squashes your error...

My error is this

Error: Configuration contains string/RegExp pattern, but no filename was passed to Babel

Setting up the docz with CRA I was able to see the difference and it is that my node_modules docz does not have its own copy of @babel/core and is not able find the file name for something... its not in the options that get passed in...

So... I still don't know what is wrong but it is probably with my setup.

1.0.4 still has this issue

This is not an issue with this library.

The issue of this library that it using broken packages. Bless patch-package I could fix it with a pretty simple patch on my side (react-docgen+4.1.0.patch):

diff --git a/node_modules/react-docgen/dist/babylon.js b/node_modules/react-docgen/dist/babylon.js
new file mode 100644
index 0000000..81d1e38
--- /dev/null
+++ b/node_modules/react-docgen/dist/babylon.js
@@ -0,0 +1 @@
+module.exports={}

I'd be happy to help out solving this issue, though I need some guidance from authors.

This is not an issue with this library.

The issue of this library that it using broken packages. Bless patch-package I could fix it with a pretty simple patch on my side (react-docgen+4.1.0.patch):

diff --git a/node_modules/react-docgen/dist/babylon.js b/node_modules/react-docgen/dist/babylon.js
new file mode 100644
index 0000000..81d1e38
--- /dev/null
+++ b/node_modules/react-docgen/dist/babylon.js
@@ -0,0 +1 @@
+module.exports={}

I'd be happy to help out solving this issue, though I need some guidance from authors.

Has solved this problem by publishing a patch version for react-docgen?

@ronghang No, I just use patch-package to apply above patch into my projects node_modules. I can't get how others doesn't suffer from this problem. It isn't possible to start docz without patches for about 1.5 months for me.
Today docz is 1.1.0 and I still have to apply this patch to start using it.

v1.2.0 still exist

Has the fix been published yet? Still getting this error in 1.2.0 (which is the default version being installed)

not that i know of. sorry :( but still clsoing this issue in meantime since its fixed but just not published yet. cc @pedronauck

Just a thought, y'all might want to add an integration test to catch these kind of things.

this issue still exists for me @^1.2.0 so not sure why this is closed

the fix is merged, but not published yet. fyi @pedronauck

any updates or any workaround pleaaase ! @pedronauck

@hamed-farag I created a workaround by just commenting out babylon = require('react-docgen/dist/babylon').default in node_modulesreact-docgen-external-proptypes-handler\index.js (line 15)

the fix is merged, but not published yet. fyi @pedronauck

The publication of release has been a bit slow recently.

yep. i've pinged pedro again. its his project 🤷🏼‍♂️

I am having the same error as a few users:

Error: Configuration contains string/RegExp pattern, but no filename was passed to Babel

This is with a basic setup. Ian yarn add docz docz-theme-default --dev in an existing project, added the docz:dev script, created ./src/HelloWorld.mdx with the basic content from the docs, and then ran docz:dev.

doesnt seem like the same issue.

@sw-yx I figured it was relevant and didn't want to create a different issue for it to be shut down and pointed to this.

This is not an issue with this library. The error you are getting is getting squashed by this.
https://github.com/siddharthkp/react-docgen-external-proptypes-handler/blob/master/index.js#L11

try {
  const buildParser = require('react-docgen/dist/babelParser').default
  babylon = buildParser()
} catch (e) {
  babylon = require('react-docgen/dist/babylon').default
}

This try catch squashes your error...

My error is this

Error: Configuration contains string/RegExp pattern, but no filename was passed to Babel

Setting up the docz with CRA I was able to see the difference and it is that my node_modules docz does not have its own copy of @babel/core and is not able find the file name for something... its not in the options that get passed in...

So... I still don't know what is wrong but it is probably with my setup.

the fix is merged, but not published yet. fyi @pedronauck

The publication of release has been a bit slow recently.

Am still waiting for the new release :(

yea i've prodded @pedronauck a couple times already. he's juggling a bunch of stuff it seems. not much i can do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clock157 picture clock157  ·  33Comments

PlayMa256 picture PlayMa256  ·  24Comments

tamagokun picture tamagokun  ·  23Comments

bugzpodder picture bugzpodder  ·  26Comments

maxguzenski picture maxguzenski  ·  24Comments