Skip to content

docsify fails under yarn pnp strict mode due to missing ansi-colors dependency #191

Open
@tripplilley

Description

@tripplilley

Yarn (v2/3) by default operates in a strict Plug'n'Play mode which does not allow directly loading indirect dependencies.

lib/commands/init.js directly requires ansi-colors, but it's not listed in package.json.

yarn run docsify, therefore, fails (even if docsify-cli is correctly registered in package.json).

Adding "ansi-colors": "^4.1.1" to dependencies should be enough (I chose that version because it's what's already in package-lock.json from an indirect dependency).

$ yarn run docsify
/Users/tlilley/projects/veatech/sbx/smithy/.pnp.cjs:11796
    throw firstError;
    ^

Error: docsify-cli tried to access ansi-colors, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: ansi-colors
Required by: docsify-cli@npm:4.4.4 (via /Users/tlilley/projects/veatech/sbx/smithy/.yarn/cache/docsify-cli-npm-4.4.4-3d7dbcc799-2f72ff07d0.zip/node_modules/docsify-cli/lib/commands/)

Require stack:
- /Users/tlilley/projects/veatech/sbx/smithy/.yarn/cache/docsify-cli-npm-4.4.4-3d7dbcc799-2f72ff07d0.zip/node_modules/docsify-cli/lib/commands/init.js
- /Users/tlilley/projects/veatech/sbx/smithy/.yarn/cache/docsify-cli-npm-4.4.4-3d7dbcc799-2f72ff07d0.zip/node_modules/docsify-cli/lib/index.js
- /Users/tlilley/projects/veatech/sbx/smithy/.yarn/cache/docsify-cli-npm-4.4.4-3d7dbcc799-2f72ff07d0.zip/node_modules/docsify-cli/bin/docsify
    at require$$0.Module._resolveFilename (/Users/tlilley/projects/veatech/sbx/smithy/.pnp.cjs:11795:13)
    at require$$0.Module._load (/Users/tlilley/projects/veatech/sbx/smithy/.pnp.cjs:11645:42)
    at Module.require (node:internal/modules/cjs/loader:1157:19)
    at require (node:internal/modules/helpers:119:18)
    at Object.<anonymous> (/Users/tlilley/projects/veatech/sbx/smithy/.yarn/cache/docsify-cli-npm-4.4.4-3d7dbcc799-2f72ff07d0.zip/node_modules/docsify-cli/lib/commands/init.js:10:16)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at require$$0.Module._extensions..js (/Users/tlilley/projects/veatech/sbx/smithy/.pnp.cjs:11839:33)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at require$$0.Module._load (/Users/tlilley/projects/veatech/sbx/smithy/.pnp.cjs:11676:14)

Node.js v19.8.1

Activity

changed the title [-]`docsify` fails under pnpm / yarn strict mode due to missing `ansi-colors` dependency[/-] [+]`docsify` fails under yarn pnp strict mode due to missing `ansi-colors` dependency[/+] on Mar 20, 2023
tripplilley

tripplilley commented on Mar 20, 2023

@tripplilley
Author

For anyone else dealing with this, you can work around it by using "loose" Plug'n'Play mode until there's an update.

$ yarn config set pnpMode loose
➤ YN0000: Successfully set pnpMode to 'loose'

You'll also need to remove the cached Plug'n'Play install file and reinstall your dependencies:

$ rm .pnp.cjs
$ yarn install
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 0s 341ms
tripplilley

tripplilley commented on Mar 20, 2023

@tripplilley
Author

Apparently there are other missing dependency declarations, too 😅

$ yarn run docsify serve -p 3006
(node:39416) [MODULE_NOT_FOUND] Error: docsify-cli tried to access ansi-colors, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:39416) [MODULE_NOT_FOUND] Error: node-fetch tried to access encoding (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
(node:39416) [MODULE_NOT_FOUND] Error: debug tried to access supports-color (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
(node:39416) [MODULE_NOT_FOUND] Error: docsify-server-renderer tried to access marked, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
(node:39416) [MODULE_NOT_FOUND] Error: docsify-server-renderer tried to access prismjs, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
(node:39416) [MODULE_NOT_FOUND] Error: docsify-server-renderer tried to access strip-indent, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
(node:39416) [MODULE_NOT_FOUND] Error: docsify-cli tried to access y18n, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
(node:39416) [MODULE_NOT_FOUND] Error: yargonaut tried to access yargs, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Using pnpMode: loose, as noted in my previous comment, still works, but that's a setting that affects the entire project, so it's really just a short-term solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      `docsify` fails under yarn pnp strict mode due to missing `ansi-colors` dependency · Issue #191 · docsifyjs/docsify-cli