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

TypeError when a dependency module depends upon Chalk - @rollup/plugin-commonjs > 23.0.4 #1446

Closed
Jason3S opened this issue Feb 27, 2023 · 2 comments · Fixed by #1455
Closed

Comments

@Jason3S
Copy link

Jason3S commented Feb 27, 2023

Expected Behavior

The app not to crash on startup. See repo:

npm run test:ok

Result is as expected:

Hello Node.js v16.14.2!
{ config: {}, filepath: '/home/projects/node-acyqrb/test-cosmic.json' }

Actual Behavior

npm run test:broken

Result:

TypeError: Cannot read properties of undefined (reading 'close')
    at eval (file://file:///home/projects/node-acyqrb/dist/index.mjs:2513:77)
    at requireChalk (file://file:///home/projects/node-acyqrb/dist/index.mjs:2670:3)
    at requireLib$1 (file://file:///home/projects/node-acyqrb/dist/index.mjs:2691:15)
    at requireLib (file://file:///home/projects/node-acyqrb/dist/index.mjs:2809:19)
    at requireParseJson (file://file:///home/projects/node-acyqrb/dist/index.mjs:2976:29)
    at Object.loadJson (file://file:///home/projects/node-acyqrb/dist/index.mjs:7141:17)
    at ExplorerSync.loadPackageProp (file://file:///home/projects/node-acyqrb/dist/index.mjs:7254:46)
    at ExplorerSync.loadFileContentSync (file://file:///home/projects/node-acyqrb/dist/index.mjs:7681:14)
    at ExplorerSync.createCosmiconfigResultSync (file://file:///home/projects/node-acyqrb/dist/index.mjs:7689:30)
    at ExplorerSync.loadSearchPlaceSync (file://file:///home/projects/node-acyqrb/dist/index.mjs:7666:17) 

Additional Information

This is a bit of a nasty issue because it is related to a nested dependency:

devDependencies:
cosmiconfig 8.1.0
└─┬ parse-json 5.2.0
  └─┬ @babel/code-frame 7.18.6
    └─┬ @babel/highlight 7.18.6
      └─┬ chalk 2.4.2
        └── ansi-styles 3.2.1

It started when upgrading Cosminconfig from 8.0.0 to 8.1.0.

See: cosmiconfig/cosmiconfig#291

I tracked this down to a change in @rollup/plugin-commonjs. Version 23.0.4 works, everything past it does not. It seems to be due to this PR.

Please open an issue in rollup's repository.

If they refuse to fix this for some reason, the package having to adapt would probably be chalk or ansi-styles, not cosmiconfig.

Originally posted by @d-fischer in cosmiconfig/cosmiconfig#291 (comment)

@coderaiser
Copy link

Using an alias with empty function helps, if chalk isn't used:

alias({
    entries: [
        {find: 'chalk', replacement: './lib/chalk.js'},
    ]
}),

@lukastaegert
Copy link
Member

Fixed by #1455

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.

3 participants