Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

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

Closed
ronghang opened this issue Mar 27, 2019 · 33 comments
Closed

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

ronghang opened this issue Mar 27, 2019 · 33 comments

Comments

@ronghang
Copy link

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
}
@pedronauck
Copy link
Member

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.

@ronghang
Copy link
Author

ronghang commented Apr 1, 2019

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 docz-core@1.0.0-rc.7

image

@higormarques
Copy link

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

@ronghang
Copy link
Author

ronghang commented Apr 4, 2019

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.

@Guria
Copy link

Guria commented Apr 4, 2019

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

@pedronauck
Copy link
Member

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

@zicodeng
Copy link

zicodeng commented Apr 5, 2019

@pedronauck

I started a new docz project and installed docz@1.0.0-rc.8 and docz-theme-default@1.0.0-rc.8. It worked great. But it still has this dependency react-docgen-external-proptypes-handler

yarn.lock

docz-core@1.0.0-rc.8:
  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

@pedronauck
Copy link
Member

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

@zicodeng
Copy link

zicodeng commented Apr 5, 2019

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

@Guria
Copy link

Guria commented Apr 5, 2019

@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

@ronghang
Copy link
Author

ronghang commented Apr 8, 2019

@pedronauck the docz-core@1.0.0-rc.8 still rely on the react-docgen-external-proptypes-handler "^1.0.2" in the package.json. Try to remove it.

@Guria
Copy link

Guria commented Apr 15, 2019

1.0.1 1.0.3 still has this issue

@bcbrian
Copy link

bcbrian commented Apr 18, 2019

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.

@gmukul01
Copy link

1.0.4 still has this issue

@Guria
Copy link

Guria commented Apr 30, 2019

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.

@ronghang
Copy link
Author

ronghang commented May 6, 2019

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?

@Guria
Copy link

Guria commented May 7, 2019

@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.

@flysouls
Copy link

v1.2.0 still exist

@swyxio
Copy link
Contributor

swyxio commented May 12, 2019

made this to fix: #866

pedronauck pushed a commit that referenced this issue May 14, 2019
see the issue for details on the typos fixed

closes issue #727
@elisoncampos
Copy link

elisoncampos commented May 22, 2019

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

@swyxio
Copy link
Contributor

swyxio commented May 22, 2019

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

@swyxio swyxio closed this as completed May 22, 2019
@nmccready
Copy link

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

@mike-egner
Copy link

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

@swyxio
Copy link
Contributor

swyxio commented Jun 4, 2019

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

@hamed-farag
Copy link

hamed-farag commented Jun 9, 2019

any updates or any workaround pleaaase ! @pedronauck

@mike-egner
Copy link

mike-egner commented Jun 9, 2019

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

@ronghang
Copy link
Author

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

The publication of release has been a bit slow recently.

@swyxio
Copy link
Contributor

swyxio commented Jun 10, 2019

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

@colshacol
Copy link

colshacol commented Jun 12, 2019

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.

@swyxio
Copy link
Contributor

swyxio commented Jun 13, 2019

doesnt seem like the same issue.

@colshacol
Copy link

@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.

@hamed-farag
Copy link

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 :(

@swyxio
Copy link
Contributor

swyxio commented Jun 24, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests