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

Uncaught TypeError: createRequire is not a function #8047

Closed
tjapro opened this issue Apr 13, 2020 · 18 comments · Fixed by #8072
Closed

Uncaught TypeError: createRequire is not a function #8047

tjapro opened this issue Apr 13, 2020 · 18 comments · Fixed by #8072
Labels
status:awaiting response Issues that require answers to questions from maintainers before action can be taken type:editor support Issues about tools Prettier provides for use inside editor integrations.

Comments

@tjapro
Copy link

tjapro commented Apr 13, 2020

Environments:

  • Prettier Version: 2.0.4
  • Running Prettier via: atom-prettier
  • Runtime: ?
  • Operating System: Linux, macOS, windows

Steps to reproduce:

Please see prettier/prettier-atom#725

Thanks!

@thorn0 thorn0 added type:bug Issues identifying ugly output, or a defect in the program type:editor support Issues about tools Prettier provides for use inside editor integrations. labels Apr 13, 2020
@thorn0
Copy link
Member

thorn0 commented Apr 13, 2020

Sounds like a Node version problem. Prettier requires Node 10.13.0+.

@thorn0 thorn0 added status:awaiting response Issues that require answers to questions from maintainers before action can be taken and removed type:bug Issues identifying ugly output, or a defect in the program labels Apr 13, 2020
@BarryThePenguin
Copy link

BarryThePenguin commented Apr 14, 2020

I'm seeing a similar issue..

Environments:

Steps to reproduce:

  1. clone https://github.com/BarryThePenguin/simple-desktop-images
  2. run npm install && npx npm-check --update-all
  3. Open the project in atom with atom-linter-xo installed
  4. Run "XO: fix" from the Atom command palette

Result

[Linter] Error running XO TypeError: createRequire is not a function

Expected

Should see lint errors

I can also create a new issue if need be..
I thought I'd ask here first before creating one in atom-linter-xo or xo

@NazarkinRoman
Copy link

Also seen this when tried to run prettier through Jetbrains IDEA plugin.

Environments:

  • Prettier Version: 2.0.4
  • Running Prettier via: Jetbrains IDEA plugin
  • Runtime: Node v10.13.0, JetBrains WebStorm 2020.1
  • Operating System: macOS

Here is the output:

TypeError: createRequire is not a function
    at Object.<anonymous> (/Users/roman/.nvm/versions/node/v10.13.0/lib/node_modules/prettier/index.js:23267:13)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at requireInContext (/Applications/WebStorm.app/Contents/plugins/prettierJS/prettierLanguageService/prettier-plugin.js:70:12)
    at PrettierPlugin.requirePrettierApi (/Applications/WebStorm.app/Contents/plugins/prettierJS/prettierLanguageService/prettier-plugin.js:44:24)
Process finished with exit code -1

@thorn0
Copy link
Member

thorn0 commented Apr 16, 2020

@NazarkinRoman You shouldn't need the plugin to use Prettier in WebStorm 2020.1. See https://prettier.io/docs/en/webstorm.html

@matepek
Copy link

matepek commented Apr 17, 2020

My tests are failing too with this error: https://travis-ci.org/github/matepek/vscode-catch2-test-adapter/jobs/675884929

@thorn0
Copy link
Member

thorn0 commented Apr 17, 2020

@matepek Your tests use vscode-loader that patches Node's require in such a way that the 2nd parameter options of require.resolve is ignored. But I can't understand why require('module').createRequire (AKA createRequireFromPath) isn't available. At least it seems like the native require should be available as require.nodeRequire.

@thorn0
Copy link
Member

thorn0 commented Apr 17, 2020

@fisker Seems like it's easier to a add a fallback to https://www.npmjs.com/package/resolve than to fight all these hacks. Thoughts?

@matepek
Copy link

matepek commented Apr 17, 2020

I downgraded to:

"prettier": "2.0.2",
"eslint-plugin-prettier": "3.1.2"

It seems working.

@fisker
Copy link
Sponsor Member

fisker commented Apr 17, 2020

@fisker Seems like it's easier to a add a fallback to npmjs.com/package/resolve than to fight all these hacks. Thoughts?

Let's do it, we don't want waste more time on this.

Edit: Sorry, I didn't read carefully, I thought you want remove use require.resolve, I think this is easier. Not need fallback.

@NazarkinRoman
Copy link

@NazarkinRoman You shouldn't need the plugin to use Prettier in WebStorm 2020.1. See https://prettier.io/docs/en/webstorm.html

This plugin was installed for long time ago so I just didn't realized that WebStorm now has native support for it. But it seems that they simply replaced old plugin with their own bundled when I updated to the latest version so the bug is still actual.

@thorn0
Copy link
Member

thorn0 commented Apr 17, 2020

I'm going to release 2.0.5 this weekend. It will include a fix for these problems (#8072).

@thorn0
Copy link
Member

thorn0 commented Apr 21, 2020

@NazarkinRoman 2.0.5 is out. Please update and check if the issue is gone.

@BarryThePenguin
Copy link

Thanks all, looks like that solved the issue 🎉

@NazarkinRoman
Copy link

@thorn0 it looks like the previous error has gone, but another one appeared while using Prettier with WebStorm:

TypeError: text.trimEnd is not a function
    at attachComments (/Users/nazarkin-roma/.nvm/versions/node/v14.0.0/lib/node_modules/prettier/index.js:14771:60)
    at coreFormat (/Users/nazarkin-roma/.nvm/versions/node/v14.0.0/lib/node_modules/prettier/index.js:14798:23)
    at format (/Users/nazarkin-roma/.nvm/versions/node/v14.0.0/lib/node_modules/prettier/index.js:15019:75)
    at formatWithCursor (/Users/nazarkin-roma/.nvm/versions/node/v14.0.0/lib/node_modules/prettier/index.js:15035:12)
    at args (/Users/nazarkin-roma/.nvm/versions/node/v14.0.0/lib/node_modules/prettier/index.js:51620:12)
    at Object.format (/Users/nazarkin-roma/.nvm/versions/node/v14.0.0/lib/node_modules/prettier/index.js:51640:12)
    at performFormat (/Applications/WebStorm.app/Contents/plugins/prettierJS/prettierLanguageService/prettier-plugin.js:66:29)
    at PrettierPlugin.handleReformatCommand (/Applications/WebStorm.app/Contents/plugins/prettierJS/prettierLanguageService/prettier-plugin.js:36:16)
    at PrettierPlugin.onMessage (/Applications/WebStorm.app/Contents/plugins/prettierJS/prettierLanguageService/prettier-plugin.js:11:33)
    at Interface.<anonymous> (/Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/jsLanguageServicesImpl/js-language-service.js:105:39)
Process finished with exit code -1

@thorn0
Copy link
Member

thorn0 commented Apr 22, 2020

@NazarkinRoman Does this happen always or only when formatting some specific piece of code? Does downgrading to 2.0.2 fix this?

@NazarkinRoman
Copy link

@thorn0 Hmm. Right now tried to run it again and it worked (for both cases: whole document and range). I'll get back to you if this error will appear again.

@acroyear
Copy link

acroyear commented Aug 1, 2020

2.0.5 (with eslint-prettier 3.1.4) did not solve the problem for me (Atom 1.44)

mpyw added a commit to mpyw/axios-case-converter that referenced this issue Oct 14, 2021
ESLint/Prettier requirement changes?
prettier/prettier#8047
@meycon1
Copy link

meycon1 commented Dec 20, 2021

I decided to do an update to borales/actions-yarn/@v2.3.0

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:awaiting response Issues that require answers to questions from maintainers before action can be taken type:editor support Issues about tools Prettier provides for use inside editor integrations.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants