remark: remark-cli and .remarkrc.js throws "Only file and data URLs are supported by the default ESM loader"

Error Message

On the latest version, remark no longer works properly on Windows, resulting in the following error:

README.md
  1:1  error  Error: Cannot parse file `.remarkrc.js`
Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at FormattedError (D:\Repositories\remark-test\node_modules\fault\index.js:29:12)
    at onparse (D:\Repositories\remark-test\node_modules\unified-engine\lib\find-up.js:152:13)
    at done (D:\Repositories\remark-test\node_modules\trough\wrap.js:55:16)

× 1 error

This is a regression because it worked just fine in the past on older versions.

Test Repo

You can easily reproduce this bug by following the steps in my test repository.

Environment

  • OS: Windows 10
  • Packages: See the package.json file in my test repository
  • Env: Node v16.3.0, npm v7.18.1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the quick reply Christian. I converted my config to the mjs format and I am good to go now.

I experienced some additional pain getting the file to lint though, which I will document here:

  1. I had to add "!.remarkrc.mjs" to the ignorePatterns section of my .eslintrc.js file, because ESLint will explicitly ignore hidden files by default. (This is necessary even if you put .remarkrc.mjs in the include section of your tsconfig.eslint.json file.)
  2. I had to add extraFileExtensions: [".mjs"], to the parserOptions section of my .eslintrc.js file, because ESLint refuses to parse mjs files otherwise.

Yes, this issue appears to be resolved now in the latest versions of everything, thanks again wooorm.