Lint-staged: Error thrown running with the [email protected] (mini repo included)

Created on 23 Mar 2018  Β·  35Comments  Β·  Source: okonet/lint-staged

Description

Steps to reproduce

mini repo at https://gist.github.com/ztan/adefcaf938a4df7ef92b62c4738b7736

  1. download the file from the gist
  2. run
npm run test

Debug Logs

C:\work\projects\sandbox\lint-staged-test> npm run test

> [email protected] test C:\work\projects\sandbox\lint-staged-test
> lint-staged -d

  lint-staged:bin Running `[email protected]` +0ms
C:\work\projects\sandbox\lint-staged-test\node_modules\any-observable\register.js:29
                throw new Error('Cannot find any-observable implementation nor' +
                ^

Error: Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").
    at loadImplementation (C:\work\projects\sandbox\lint-staged-test\node_modules\any-observable\register.js:29:9)
    at register (C:\work\projects\sandbox\lint-staged-test\node_modules\any-observable\loader.js:32:18)
    at Object.<anonymous> (C:\work\projects\sandbox\lint-staged-test\node_modules\any-observable\index.js:2:39)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `lint-staged -d`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ztan\AppData\Roaming\npm-cache\_logs\2018-03-23T02_28_36_078Z-debug.log


expand to view

COPY THE DEBUG LOGS HERE

Environment

  • OS: Windows 10
  • Node.js: 8.9.1
  • lint-staged: 7.0.0

Most helpful comment

It seems Listr depends on RxJS, and because it hasn't been updated to support RxJS 6, a compatibility package rxjs-compat is required. Once this package is installed, the issue goes away.

All 35 comments

lint-staged doesn't use any of these dependencies so I'm not sure what's going on but I highly doubt it's this package fault. Please investigate further to the root cause.

It seems Listr depends on RxJS, and because it hasn't been updated to support RxJS 6, a compatibility package rxjs-compat is required. Once this package is installed, the issue goes away.

Thanks @ztan for getting to the bottom of that.

@sudo-suhas the solution for us users is for you to update your dependency on listr to 0.14 which has updated to support rxjs 6 and release a patch. πŸ˜„ https://github.com/SamVerschueren/listr/blob/master/package.json#L54

It's not that simple. Please see #426

I'm still having this error. Installing rxjs-compat did not fix it.

$ npx lint-staged
Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").

lint-staged 7.2.0
listr 0.14.1

ping @SamVerschueren

@brunolemos Can you clean up your node_modules and install everything again? It looks like it still uses an older version of any-observable.

@SamVerschueren thanks! Deleting node_modules did not do the trick, but deleting package-lock.json did.

_PS: any-observable was already on the latest version, so it was something else. Here is the commit with the package-lock.json changes._

In my case, I've tried completely deleting both node_modules and my lockfile (yarn.lock in my case, but presumably should be the same deal as NPM's package-lock) and it didn't make a difference. I tried this both before and after adding rxjs-compat.

Anyone else have any suggestions?

You could double check the package versions you are pulling in

We could investigate the issue if you can share a minimal repo which can reproduce the issue.

I appear to be pulling in lint-staged@^7.2.0, listr@^0.14.1, and any-observable@^0.3.0, which leads to me believe this should be working?

If I can't get this sorted out soon, I'll try to throw together a minimal failing example. Thanks for the quick reply!

It appears my issue was in yarn. Running a yarn cache clean before nuking my node_modules/etc seems to have cleaned everything up.

I cannot get around this error. I've tried wiping my caches and all the locks and node_modules and so on, but continue hitting it. So this is making lint-staged unusable for me on a certain project :(

Here are my relevant dependency versions:

```
└─┬ [email protected]
└─┬ [email protected]
└─┬ @samverschueren/[email protected]
└── [email protected]
````

Ugh, it seemed to have resolved itself just by me npm ciing enough? Sorry for the noise. Hope it doesn't come back.

I just ran into this as well on https://github.com/okonet/eslint-config-okonet

Node: 10.3.0

BUT then I run pre-commit I see

husky > npm run -s precommit (node v8.11.2)

Not sure where it's coming from since I don't have .nvmrc there :-/

Full output here:

Projects/OSS/eslint-config-okonet on ξ‚  feature-upgrade-all [+] is πŸ“¦  v0.0.0-development via β¬’ v10.3.0 
➜ gc  
husky > npm run -s precommit (node v8.11.2)

/Users/okonet/Projects/OSS/eslint-config-okonet/node_modules/any-observable/register.js:29
        throw new Error('Cannot find any-observable implementation nor' +
        ^

Error: Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").
    at loadImplementation (/Users/okonet/Projects/OSS/eslint-config-okonet/node_modules/any-observable/register.js:29:9)
    at /Users/okonet/Projects/OSS/eslint-config-okonet/node_modules/any-observable/loader.js:30:18
    at Object.<anonymous> (/Users/okonet/Projects/OSS/eslint-config-okonet/node_modules/any-observable/index.js:2:39)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

husky > pre-commit hook failed (add --no-verify to bypass)

Just had the same issue while running with lint-staged version 7.0.4

I just updated to 7.2.2 and the issue is gone

yarn cache clean then yarn add --dev lint-staged@^7.2.0 worked for me.

just ran into this issue on v7.2.2.

I updated my node to v10.10.0 and did a npm install --save-dev lint-staged husky (even though I already had both dependencies updated in place) and it worked.

For me this issue came out of the blue after adding "rxjs" as dev dependency (needed it for some unit tests)

I fixed it by adding rxjs-compat as dev dependency as well.

So it looks like husky or any-observable is obscurely trying to find rxjs in the node_modules, working correctly (maybe polyfilling) if it is _not_ installed, but breaking as soon as rxjs _is_ added to the dependencies

Interesting. That’s something we could try reproducing. But I think the fix should go to Listr

I've run into the same error message, but when using @pnpm to install lint-staged.

See here: https://github.com/pnpm/pnpm/issues/1496

I ran into the same error when I added rxjs to my projects. I'm using Lerna with yarn(workspaces), Husky, lint-staged. Monorepo setup
I'm using rxjs 6.3.3 which requires lint-staged 7.1.1
and I'm using lint-staged 8.1.0
The issue is when within the above combination of packages lint-staged is hoisted and all it's dependencies and it just breaks with not module found when internally running any-observable
adding to my root package.json under workspaces (yarn) "nohoist": ["/rxjs","/lint-staged","/lint-staged/"] fixed the issue.
Down the path of all deps of lint-staged they need to be adapted for monorepo environment

I've opened https://github.com/SamVerschueren/listr/pull/127 to fix the pnpm issue.

Updated to latest list-staged version solved it for me.

yarn cache clean did the tricky for me, thank you @enesTufekci

Upgrading lint-staged to 8.1.1 solved the issue

@0xc0d3r thanks! That seems to fix it for me as well.

Update: I resolved the issue. See below for problem details and the solution steps.

I've tried everything on this thread and am still getting the same issue.

Configuration

  • Monorepo using Yarn Workspaces but NOT Lerna
  • Node v10.15.3
  • Yarn 1.15.2
# .nvmrc
v10.15.3
# yarn.lock -- all packages mentioned in this thread
lint-staged@^8.2.1:
  version "8.2.1"
  resolved "https://pkgs.dev.azure.com/frontporch/_packaging/fp-internal/npm/registry/lint-staged/-/lint-staged-8.2.1.tgz#752fcf222d9d28f323a3b80f1e668f3654ff221f"
  integrity sha1-dS/PIi2dKPMjo7gPHmaPNlT/Ih8=
  dependencies:
    chalk "^2.3.1"
    commander "^2.14.1"
    cosmiconfig "^5.2.0"
    debug "^3.1.0"
    dedent "^0.7.0"
    del "^3.0.0"
    execa "^1.0.0"
    g-status "^2.0.2"
    is-glob "^4.0.0"
    is-windows "^1.0.2"
    listr "^0.14.2"
    listr-update-renderer "^0.5.0"
    lodash "^4.17.11"
    log-symbols "^2.2.0"
    micromatch "^3.1.8"
    npm-which "^3.0.1"
    p-map "^1.1.1"
    path-is-inside "^1.0.2"
    pify "^3.0.0"
    please-upgrade-node "^3.0.2"
    staged-git-files "1.1.2"
    string-argv "^0.0.2"
    stringify-object "^3.2.2"
    yup "^0.27.0"

listr@^0.14.2:
  version "0.14.3"
  resolved "https://pkgs.dev.azure.com/frontporch/_packaging/fp-internal/npm/registry/listr/-/listr-0.14.3.tgz#2fea909604e434be464c50bddba0d496928fa586"
  integrity sha1-L+qQlgTkNL5GTFC926DUlpKPpYY=
  dependencies:
    "@samverschueren/stream-to-observable" "^0.3.0"
    is-observable "^1.1.0"
    is-promise "^2.1.0"
    is-stream "^1.1.0"
    listr-silent-renderer "^1.1.1"
    listr-update-renderer "^0.5.0"
    listr-verbose-renderer "^0.5.0"
    p-map "^2.0.0"
    rxjs "^6.3.3"

rxjs@^6.3.3, rxjs@^6.4.0:
  version "6.5.2"
  resolved "https://pkgs.dev.azure.com/frontporch/_packaging/fp-internal/npm/registry/rxjs/-/rxjs-6.5.2.tgz#2e35ce815cd46d84d02a209fb4e5921e051dbec7"
  integrity sha1-LjXOgVzUbYTQKiCftOWSHgUdvsc=
  dependencies:
    tslib "^1.9.0"

rxjs@~6.2.1:
  version "6.2.2"
  resolved "https://pkgs.dev.azure.com/frontporch/_packaging/fp-internal/npm/registry/rxjs/-/rxjs-6.2.2.tgz#eb75fa3c186ff5289907d06483a77884586e1cf9"
  integrity sha1-63X6PBhv9SiZB9Bkg6d4hFhuHPk=
  dependencies:
    tslib "^1.9.0"
// root package.json
{
  "workspaces": {
    // ...
    "nohoist": [
      "**/api/**",
      "**/shared/**",
      "**/web/**",
      "husky",
      "lint-staged"
    ],
  },
  "devDependencies": {
    "doctoc": "^1.4.0",
    "husky": "^2.4.1",
    "lint-staged": "^8.2.1",
    "npm-run-all": "^4.1.5",
    "prettier": "~1.18.2"
  }
}

Errors

$ git add . -A
$ git commit -m "My commit message"
husky > pre-commit (node v10.15.3)
/Users/rpass/FrontPorch/mobius/node_modules/any-observable/register.js:29
        throw new Error('Cannot find any-observable implementation nor' +
        ^

Error: Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").
    at loadImplementation (/Users/rpass/FrontPorch/mobius/node_modules/any-observable/register.js:29:9)
    at /Users/rpass/FrontPorch/mobius/node_modules/any-observable/loader.js:30:18
    at Object.<anonymous> (/Users/rpass/FrontPorch/mobius/node_modules/any-observable/index.js:2:39)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
husky > pre-commit hook failed (add --no-verify to bypass)
$ npx lint-staged -d
  lint-staged:bin Running `[email protected]` +0ms
Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").

What I've tried

On each attempt/iteration, I did yarn cache clean && yarn rimraf:node_modules && yarn install. yarn rimraf:node_modules just does rm -rf node_modules on each package.

  • Adding a .nvmrc
  • Reverting Node to 8.16.0
  • yarn add rxjs -D -W
  • yarn add rxjs-compat -D -W
  • Adding all the additional nohoist paths that @alecorsino mentioned
  • yarn add husky -D -W && yarn add lint-staged -D -W

Resolution

// root package.json
{
  "workspaces": {
    "nohoist": [
      "**/api/**",
      "**/shared/**",
      "**/web/**",
      "husky",
      "lint-staged",
      "lint-staged/**" // add this
    ]
  },
  "devDependencies": {
    "doctoc": "^1.4.0",
    "husky": "^2.6.0", // upgrade this
    "lint-staged": "^8.2.1",
    "npm-run-all": "^4.1.5",
    "prettier": "~1.18.2"
  }
}
  • yarn cache clean && yarn rimraf && yarn install && npx lint-staged -d passes πŸŽ‰

    • yarn rimraf just runs rm-rf node_modules everywhere applicable

Upgrading list-staged to 8.1.1 solved the isssue

Firstly,thanks,It fixed my problem.But list-staged name error.The right is lint-staged

Today:

npx lint-staged

Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").

Yesterday:
npx lint-staged

No staged files match any of provided globs.

I am on lint-staged ^9.2.1. I swear it was working fine yesterday, well today....

By removing node_modules folder and package.lock file, it worked again.

I have a question, during pre-commit, why dose lint-staged execute .js files in any-observable?

Regarding the messages from this thread, lint-staged doesn't use anything related to any-observable, with this being said, it shouldn't execute .js file in any-observable.

Still have this issue

Was this page helpful?
0 / 5 - 0 ratings