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

chalk imported from npm:prettier is somehow incomplete #21269

Closed
yamavol opened this issue Nov 20, 2023 · 4 comments
Closed

chalk imported from npm:prettier is somehow incomplete #21269

yamavol opened this issue Nov 20, 2023 · 4 comments
Labels
working as designed this is working as intended

Comments

@yamavol
Copy link

yamavol commented Nov 20, 2023

This deno code threw an error

import prettier from 'npm:prettier@3.1.0';
await prettier.format('</p>', { parser: 'html'});
/* TypeError: Cannot read properties of undefined (reading 'bold') */

but I was expecting this error to be thrown. (This is a node.js script)

const prettier = require('prettier')
prettier.format('</p>', { parser: 'html'});
/* SyntaxError: Unexpected closing tag "p". It may happen when the tag has 
    already been closed by another tag. */

The error is thrown from prettier lib

function getDefs(chalk2) {
  return {
    keyword: chalk2.cyan,     // these properties are defined...
    capitalized: chalk2.yellow,
    jsxIdentifier: chalk2.yellow,
    punctuator: chalk2.yellow,
    number: chalk2.magenta,
    string: chalk2.green,
    regex: chalk2.magenta,
    comment: chalk2.grey,
    invalid: chalk2.white.bgRed.bold   // but bgRed is undefined
  };
}

...which was strange. This indicates npm:chalk imported from npm:prettier is incomplete.

This code works fine in Node.js, so I think it is deno related. I know npm support is still on progress, but does this issue reproduce? Is this a known issue?

#13321 states that old version of chalk do not work with deno, but I npm:prettier is depending on chalk@5, so I think it is a different issue. I also found this error will not reproduce if I launch and attach the debugger (using VSCode). I have no clue about this behavior.

my environment:

deno --version
deno 1.38.2 (release, x86_64-pc-windows-msvc)
v8 12.0.267.1
typescript 5.2.2

tips:

import chalk from "npm:chalk@5.3.0";
console.log(chalk.white.bgRed.bold('abc')); // this was ok
@lucacasonato
Copy link
Member

Can you post your deno.lock file?

@yamavol
Copy link
Author

yamavol commented Nov 20, 2023

deno.lock

{
  "version": "3",
  "packages": {
    "specifiers": {
      "npm:chalk@5.3.0": "npm:chalk@5.3.0",
      "npm:prettier@3.1.0": "npm:prettier@3.1.0"
    },
    "npm": {
      "chalk@5.3.0": {
        "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
        "dependencies": {}
      },
      "prettier@3.1.0": {
        "integrity": "sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==",
        "dependencies": {}
      }
    }
  },
  "remote": {}
}

@lucacasonato lucacasonato added the needs investigation requires further investigation before determining if it is an issue or not label Nov 20, 2023
@dsherret
Copy link
Member

dsherret commented Nov 20, 2023

This is because chalk2 relies on the __proto__ and prettier bundles chalk 2. Prettier should upgrade to a more modern version of chalk. Related: #16775

@dsherret dsherret added bug Something isn't working and removed needs investigation requires further investigation before determining if it is an issue or not labels Nov 20, 2023
@dsherret dsherret removed their assignment Nov 20, 2023
@dsherret dsherret added working as designed this is working as intended and removed bug Something isn't working labels Nov 20, 2023
@dsherret
Copy link
Member

dsherret commented Nov 20, 2023

Closing as working as designed. Deno doesn't allow __proto__ for security reasons. This will be fixed once Babel 8 is released and prettier upgrades to that. Babel 8 uses a more modern chalk version that doesn't use __proto__.

I opened #21276 to potentiatlly have a way to opt-into enabling this.

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
working as designed this is working as intended
Projects
None yet
Development

No branches or pull requests

3 participants