question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing prettier as a dependency breaks compilation

See original GitHub issue

Please note

I am well aware that having Prettier as an imported dependency is an unusual use case and I am still confident that it is what I want. What I am working on requires formatting code that the end user has entered. I’m not saying this to be snarky, I just know it’s the first question I’d have 😃

Is this a bug report?

Yes.

Did you try recovering your dependencies?

Yes, I have created a new CRA project, installed prettier as the only extra dependency and upgraded yarn before installing.

Which terms did you search for in User Guide?

“compile”, “failed to compile”, “module parse failed”, “loader”

Environment

  1. node -v: v8.4.0
  2. npm -v: v5.6.0
  3. yarn --version (if you use Yarn): 1.3.2
  4. npm ls react-scripts (if you haven’t ejected):

prettier-test@0.0.1 └── react-scripts@1.1.0

Operating system: macos Sierra 10.12.6

Steps to Reproduce

You can reproduce the issue by doing the following:

  1. npx creat-react-app CRA-prettier-test.git && cd CRA-prettier-test
  2. yarn
  3. yarn add prettier
  4. Add import prettier from "prettier"; to the top of ./src/index.js
  5. yarn start

The problem is that this project will not compile.

Expected Behavior

That prettier doesn’t break compilation! If you comment out the prettier import at ./src/index.js:6 in my example project this is the behaviour you should see.

Actual Behavior

The project should immediately show the following error:

screen shot 2018-02-08 at 11 51 46

Reproducible Demo

I’ve created a very simple example project demonstrating the problem at https://github.com/tonyonodi/CRA-prettier-test you can use it to replicate the problem with

  1. git clone https://github.com/tonyonodi/CRA-prettier-test.git && cd CRA-prettier-test
  2. yarn
  3. yarn start

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
heyimalexcommented, Feb 9, 2018

Here’s the relevant issue.

@tonyonodi you should also subscribe to this issue since apparently latest prettier can’t run in-browser right now anyway.

1reaction
nickmccurdycommented, Apr 28, 2018

This is an issue with using Prettier on the web, not CRA: https://github.com/prettier/prettier/issues/3296

Read more comments on GitHub >

github_iconTop Results From Across the Web

Releasing Prettier 1.0
In case you don't know, prettier is a JavaScript formatter that works by compiling your code to an AST, and then pretty-printing the...
Read more >
My create-react-app is failing to compile due to ESLint error
Install patch-package and postinstall-postinstall as dev dependency . Go to node_modules/react-scripts/config/webpack.config.js and make the ...
Read more >
How to Setup ESLint and Prettier for Your React Apps
Extend the eslint:recommended configuration; Tell ESLint we'll use CommonJS global variables ( require instead of import ); Specify we'll write ...
Read more >
prettier-plugin-organize-imports - npm
A plugin that makes Prettier organize your imports (i. e. sorts, combines and removes unused ones) using the organizeImports feature of the ...
Read more >
Circular Dependencies in C++ - pvigier's blog
The most obvious one is to design well the project with independent modules or even to break a big project in smaller libraries....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found