Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docusaurus does not require *its* dependencies via babel when building (crashes when installed via pnpm) #1574

Closed
Ten0 opened this issue Jun 6, 2019 · 0 comments · Fixed by #1575

Comments

@Ten0
Copy link

Ten0 commented Jun 6, 2019

🐛 Bug Report

Docusaurus seems to require babel plugins in a way that makes babel search for them in the dependencies of the documentation project we created instead of in the dependencies of docusaurus.

This causes a build crash if the dependencies are installed in a way that prevents this kind of weird require pattern from working, for instance if docusaurus was installed via pnpm.
I'm a bit surprised this wasn't already reported by at least the pnpm team considering pnpm is using docusaurus for its own documentation, but I guess that's still what it is.

To Reproduce

  1. Create a pnpm workspace (path/to/workspace)
  2. Create a Docusaurus project inside (with the docusaurus dependency, our package is named APIPackaging
  3. Run node_modules/.bin/docusaurus-build

Expected behavior

It builds normally

Actual Behavior

It crashes, babel failing to resolve depdendencies on one of its plugins.

> NODE_OPTIONS='--stack-trace-limit=10000' node_modules/.bin/docusaurus-build

path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/files/plugins.js:152
    throw e;
    ^
Error: Cannot find module '@babel/plugin-proposal-class-properties' from 'path/to/workspace/APIPackaging/src/website'
    at Function.module.exports [as sync] (path/to/workspace/node_modules/.registry.npmjs.org/resolve/1.11.1/node_modules/resolve/lib/sync.js:71:15)
    at resolveStandardizedName (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
    at resolvePlugin (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
    at loadPlugin (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
    at createDescriptor (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at items.map (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPluginDescriptors (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
    at alias (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-descriptors.js:63:49)
    at cachedFunction (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/caching.js:33:19)
    at plugins.plugins (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-descriptors.js:28:77)
    at mergeChainOpts (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-chain.js:319:26)
    at path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at buildRootChain (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/config-chain.js:68:29)
    at loadPrivatePartialConfig (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/partial.js:85:55)
    at loadFullConfig (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/full.js:43:39)
    at loadOptions (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/config/index.js:27:36)
    at OptionManager.init (path/to/workspace/node_modules/.registry.npmjs.org/@babel/core/7.4.5/node_modules/@babel/core/lib/index.js:231:36)
    at compile (path/to/workspace/node_modules/.registry.npmjs.org/@babel/register/7.4.4_@babel+core@7.4.5/node_modules/@babel/register/lib/node.js:61:42)
    at compileHook (path/to/workspace/node_modules/.registry.npmjs.org/@babel/register/7.4.4_@babel+core@7.4.5/node_modules/@babel/register/lib/node.js:102:12)
    at Module._compile (path/to/workspace/node_modules/.registry.npmjs.org/pirates/4.0.1/node_modules/pirates/lib/index.js:93:29)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.newLoader [as .js] (path/to/workspace/node_modules/.registry.npmjs.org/pirates/4.0.1/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (path/to/workspace/node_modules/.registry.npmjs.org/docusaurus/1.11.0/node_modules/docusaurus/lib/build-files.js:36:18)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

Reproducible Demo

Unfortunately we can't publish our code but hello worlds from both projects should reproduce the issue.

A bit of digging/beginning of fix

The crash seems to be caused by that babel attempts to require dependencies from the docusaurus project we've created instead of requiring them from the docusaurus dependency, when called in docusaurus/lib/build-files.js:36.
The fact babel requires this way is we beleive somewhat mentionned in the babel documentation here (in an a bit ambiguous way).

Someone seems to have had a similar issue with expo here and fixed it by using requires instead of named dependencies.
Note: Because of the way these modules are created, we should probably use require('xxx').default instead of just require('xxx') like what was done in that issue.

Workaround

Adding the dependencies that are required by docusaurus/lib/build-files.js to our APIPackaging project makes babel able to find these, and build.
NB: Asking people to add internal dependencies of docusaurus to their project is of course not a proper fix.

Elrendio added a commit to Elrendio/Docusaurus that referenced this issue Jun 6, 2019
**What it does:**
 - Directly require babel dependencies instead of asking babel to do it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant