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

Not working with yarn 3.6.3 in pnp mode #1319

Open
mauro-ni opened this issue Aug 31, 2023 · 4 comments
Open

Not working with yarn 3.6.3 in pnp mode #1319

mauro-ni opened this issue Aug 31, 2023 · 4 comments

Comments

@mauro-ni
Copy link

Description

In a project using yarn 3.6.3 in pnp mode, I'm not able to use husky + lint-staged as pre-commit hook.

My .yarnrc.yml file:

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
    spec: "@yarnpkg/plugin-interactive-tools"

pnpEnableEsmLoader: true

yarnPath: .yarn/releases/yarn-3.6.3.cjs

Relevant section in package.json

...

"scripts": {
   ...
    "postinstall": "husky install"
  },
"lint-staged": {
    "*.{js,jsx}": [
      "eslint --fix",
      "prettier --write"
    ],
    "*": "prettier --ignore-unknown  --write"
  },

...

Steps to reproduce

Create an application based on yarn 3 + pnp mode, add lint-staged, configure it and then run

yarn run lint-staged

Debug Logs

expand to view
[PATH TO MY APP]/.yarn/cache/lint-staged-npm-14.0.1-50e37043be-8c5d740cb3.zip/node_modules/lint-staged/lib/loadConfig.js:4
import { lilconfig } from 'lilconfig'
         ^^^^^^^^^
SyntaxError: Named export 'lilconfig' not found. The requested module 'lilconfig' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'lilconfig';
const { lilconfig } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:122:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:188:5)
    at async CustomizedModuleLoader.import (node:internal/modules/esm/loader:228:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1

Environment

  • OS: macOS Ventura 13.5.1
  • Node.js: 20.5.1
  • lint-staged: 14.0.1
@iiroj
Copy link
Member

iiroj commented Aug 31, 2023

This is a weird issue, haven't seen it before. If you do the proposed change here, does it work?

https://github.com/okonet/lint-staged/blob/fc3bfeabae29b65f99b6911a989b0b41d3d1128e/lib/loadConfig.js#L4

@mauro-ni
Copy link
Author

mauro-ni commented Sep 1, 2023

@iiroj many thanks for the reply.

I did what you suggested:
https://github.com/mauro-ni/lint-staged/blob/master/lib/loadConfig.js#L4-L5

It now works.

Are you going to integrate this change? Do I have to create a pull request?

Mauro

@iiroj
Copy link
Member

iiroj commented Sep 2, 2023

Hello, yes, Pull request is welcome! I would just move the const { lilconfig } = pkg line after all the imports, to keep the imports nicely separate from other code. 👍

@mauro-ni
Copy link
Author

mauro-ni commented Sep 2, 2023

#1320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants