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

Cannot find module 'json-schema' #2009

Closed
koooge opened this issue May 11, 2020 · 7 comments · Fixed by #2010
Closed

Cannot find module 'json-schema' #2009

koooge opened this issue May 11, 2020 · 7 comments · Fixed by #2010
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@koooge
Copy link
Contributor

koooge commented May 11, 2020

Hi there,
I found an issue of @typescript-eslint/eslint-plugin or @typescript-eslint/parser 2.32.0.

Repro

$ npx eslint --ext .js,.ts .
{
  "rules": {
    "@typescript-eslint/<rule>": ["<setting>"]
  }
}
// your repro code case

Expected Result

Actual Result

Error: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.js » ./index.js#overrides[0] » ./rules/typescript': Cannot find module 'json-schema'
Require stack:
- /Users/koooge/eslint-config-foo/node_modules/@typescript-eslint/experimental-utils/dist/json-schema.js
- /Users/koooge/eslint-config-foo/node_modules/@typescript-eslint/experimental-utils/dist/index.js
- /Users/koooge/eslint-config-foo/node_modules/@typescript-eslint/eslint-plugin/dist/rules/adjacent-overload-signatures.js
- /Users/koooge/eslint-config-foo/node_modules/@typescript-eslint/eslint-plugin/dist/rules/index.js
- /Users/koooge/eslint-config-foo/node_modules/@typescript-eslint/eslint-plugin/dist/index.js
- /Users/koooge/eslint-config-foo/node_modules/eslint/lib/cli-engine/config-array-factory.js
- /Users/koooge/eslint-config-foo/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js
- /Users/koooge/eslint-config-foo/node_modules/eslint/lib/cli-engine/cli-engine.js
- /Users/koooge/eslint-config-foo/node_modules/eslint/lib/cli-engine/index.js
- /Users/koooge/eslint-config-foo/node_modules/eslint/lib/cli.js
- /Users/koooge/eslint-config-foo/node_modules/eslint/bin/eslint.js
Referenced from: /Users/koooge/eslint-config-foo/rules/typescript.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (/Users/koooge/eslint-config-foo/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/Users/koooge/eslint-config-foo/node_modules/@typescript-eslint/experimental-utils/dist/json-schema.js:7:10)
    at Module._compile (/Users/koooge/eslint-config-foo/node_modules/v8-compile-cache/v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! eslint-config-foo@0.0.1 test: `eslint --ext .js,.ts .`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the eslint-config-foo@0.0.1 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!     /Users/koooge/.npm/_logs/2020-05-11T17_59_00_930Z-debug.log

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.32.0
@typescript-eslint/parser 2.32.0
TypeScript 3.8.3
ESLint 6.8.0
node 12.16.3
npm 6.14.5
@koooge koooge added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels May 11, 2020
@derekparsons718
Copy link

I also encountered this error when I updated eslint-plugin and parser from v2.31.0 to v2.32.0.

The error disappeared when I reverted back to v2.31.0.

@AviVahl
Copy link

AviVahl commented May 11, 2020

experimental-utils re-exports a type-only package json-schema. should use type only imports/exports to avoid the require('json-schema') in transpiled .js.

Could also avoid re-exporting a type package, and use something like type JSONSchema4 = import('json-schema').JSONSchema4; in places that consume the types.

@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels May 11, 2020
@bradzacher
Copy link
Member

bradzacher commented May 11, 2020

ahhhh fudge.

This happened because of #2007.
I recreated the lock file as part of updating all of our dependencies.

This updated the @types/json-schema version from 7.0.3 to 7.0.4.
The only change between those versions was DefinitelyTyped/DefinitelyTyped#40924, which added function declarations to a previously type-only package.

Thus TS no longer scrubs the require for the package from the output.

This wasn't caught by our CI because we have a transitive dependency on the json-schema package.

@bradzacher bradzacher pinned this issue May 11, 2020
linkinchow added a commit to hannesne/projectnewcastle that referenced this issue May 12, 2020
* Basic scaffolding for a new function app, including dev container. Will add testing and code architecture stuff with first function implementation.

* Added eslint

* Implemented crate patient on patient controller.

* Implemented create patient endpoint.

* Changed name of patient shardkey

* Updated readme and changed success response to created response.

* Added RetryCollection

* Added LoggingCollection to log mongo dependency calls to app insights. Still needs tests for the logging collection.

* Added tests for LoggingCollection

* close the connection in after function; otherwise mocha hangs and won't exit

* use eslint-plugin and parser 2.31.0 & fix lint issue

typescript-eslint/typescript-eslint#2009
typescript-eslint/typescript-eslint#2010

Co-authored-by: Hannes Nel <hannesne@microsoft.com>
Co-authored-by: Wenjun Zhou <176547141@qq.com>
zckrs added a commit to radiofrance/eslint-config-radiofrance-typescript that referenced this issue May 12, 2020
@carnun
Copy link

carnun commented May 12, 2020

Hiya,
I see this has been closed, however I'm running on the latest plugins and I'm still getting this error. Is there anything that I'm missing?

  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.32.0",
    "@typescript-eslint/eslint-plugin-tslint": "^2.32.0",
    "@typescript-eslint/parser": "^2.32.0",
  }
ESLint: 7.0.0

Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.js': Cannot find module 'json-schema'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (/Users/me/code/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/Users/me/code/node_modules/@typescript-eslint/experimental-utils/dist/json-schema.js:7:10)
    at Module._compile (/Users/me/code/node_modules/v8-compile-cache/v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

@bradzacher
Copy link
Member

The fix has been released to the canary tag.
This has not been released to the latest tag yet.
It will be released when we are able to do one.

@KifKick
Copy link

KifKick commented May 12, 2020

@carnun You need to wait when new version will be released.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators May 12, 2020
@bradzacher
Copy link
Member

The fix has been released to latest - 2.33.0

@bradzacher bradzacher unpinned this issue May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants