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

.eslintrc.js linked to @wordpress/scripts may cause "The "path" argument must be of type string. Received type undefined" error #20235

Closed
ocean90 opened this issue Feb 14, 2020 · 4 comments · Fixed by #22771
Labels
Needs Testing Needs further testing to be confirmed. [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended

Comments

@ocean90
Copy link
Member

ocean90 commented Feb 14, 2020

Describe the bug
To ensure VSCode is using the same ESLint config as wp-scripts lint-js I created a file .eslintrc.js with

const defaultConfig = require('./node_modules/@wordpress/scripts/config/.eslintrc.js' );
module.exports = defaultConfig;

This is working fine unless the project is a sub-project.
image

To reproduce
Steps to reproduce the behavior:

  1. Create a directory project
  2. Inside that directory create a directory named sub-project
  3. In sub-project create package.json with
    {
      "name": "test",
      "devDependencies": {
        "@wordpress/scripts": "^7.1.0"
      }
    }
  4. In sub-project create .eslintrc.js with
    const defaultConfig = require('./node_modules/@wordpress/scripts/config/.eslintrc.js' );
    module.exports = defaultConfig;
  5. Run npm i
  6. Open the directory project in VSCode
  7. In sub-project create a file test.js with console.log( "Hello World" );
  8. Notice that no linting error is shown.

In the console of ESLint you should also see this line:

[Info  - 11:43:54] Cannot read config file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js Error: The "path" argument must be of type string. Received type undefined

I tracked this down to

path.join( path.dirname( getPackagePath() ), fileName );
where getPackagePath() is returning undefined.

If sub-project is directly opened in VS Code the path returned by getPackagePath() is /Users/Dominik/Desktop/project/sub-project/package.json

Additional context

Debug log of VS Code
[Info  - 11:31:55] ESLint server stopped.
[Info  - 11:31:56] ESLint server running in node v12.4.0
[Info  - 11:31:56] ESLint server is running.
[Info  - 11:31:56] ESLint library loaded from: /Users/Dominik/Desktop/project/sub-project/node_modules/eslint/lib/api.js
2020-02-14T10:31:56.650Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:31:56.652Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:31:56.653Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:31:56.653Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:31:56.653Z eslint:cascading-config-array-factory Load config files for /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils.
2020-02-14T10:31:56.653Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils.
2020-02-14T10:31:56.654Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils
2020-02-14T10:31:56.654Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts.
2020-02-14T10:31:56.654Z eslint:config-array-factory Loading package.json config file: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/package.json
2020-02-14T10:31:56.654Z eslint:config-array-factory Loading JSON config file: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/package.json
2020-02-14T10:31:56.655Z eslint:config-array-factory Error reading package.json file: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/package.json
2020-02-14T10:31:56.655Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts
2020-02-14T10:31:56.655Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress.
2020-02-14T10:31:56.655Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress
2020-02-14T10:31:56.655Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules.
2020-02-14T10:31:56.655Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules
2020-02-14T10:31:56.655Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project.
2020-02-14T10:31:56.656Z eslint:config-array-factory Loading JS config file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
getPackagePath:undefined <--- The error, console.log for getPackagePath() added by myself
2020-02-14T10:31:56.793Z eslint:config-array-factory Error reading JavaScript file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
(node:52624) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107:11)
    at Object.dirname (path.js:1121:5)
    at fromProjectRoot (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:13:18)
    at hasProjectFile (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:16:14)
    at hasPrettierConfig (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/config.js:35:2)
    at Object.<anonymous> (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/config/.eslintrc.js:20:8)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
(node:52624) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107:11)
    at Object.dirname (path.js:1121:5)
    at fromProjectRoot (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:13:18)
    at hasProjectFile (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:16:14)
    at hasPrettierConfig (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/config.js:35:2)
    at Object.<anonymous> (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/config/.eslintrc.js:20:8)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
(node:52624) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:52624) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:52624) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:52624) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2020-02-14T10:31:56.795Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:31:56.795Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:31:56.795Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:31:56.795Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:31:56.796Z eslint:cascading-config-array-factory Load config files for /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils.
2020-02-14T10:31:56.796Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils.
2020-02-14T10:31:56.796Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils
2020-02-14T10:31:56.796Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts.
2020-02-14T10:31:56.796Z eslint:config-array-factory Loading package.json config file: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/package.json
2020-02-14T10:31:56.796Z eslint:config-array-factory Loading JSON config file: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/package.json
2020-02-14T10:31:56.797Z eslint:config-array-factory Error reading package.json file: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/package.json
2020-02-14T10:31:56.797Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts
2020-02-14T10:31:56.797Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress.
2020-02-14T10:31:56.797Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress
2020-02-14T10:31:56.797Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project/node_modules.
2020-02-14T10:31:56.797Z eslint:config-array-factory Config file not found on /Users/Dominik/Desktop/project/sub-project/node_modules
2020-02-14T10:31:56.797Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project.
2020-02-14T10:31:56.797Z eslint:config-array-factory Loading JS config file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
2020-02-14T10:31:56.798Z eslint:config-array-factory Error reading JavaScript file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
[Info  - 11:31:56] Cannot read config file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js Error: The "path" argument must be of type string. Received type undefined
2020-02-14T10:43:54.939Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:43:54.939Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:43:54.939Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:43:54.939Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:43:54.939Z eslint:cascading-config-array-factory Load config files for /Users/Dominik/Desktop/project/sub-project.
2020-02-14T10:43:54.939Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project.
2020-02-14T10:43:54.940Z eslint:config-array-factory Loading JS config file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
2020-02-14T10:43:54.940Z eslint:config-array-factory Error reading JavaScript file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
(node:52624) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107:11)
    at Object.dirname (path.js:1121:5)
    at fromProjectRoot (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:13:18)
    at hasProjectFile (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:16:14)
    at hasPrettierConfig (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/config.js:35:2)
    at Object.<anonymous> (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/config/.eslintrc.js:20:8)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
(node:52624) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107:11)
    at Object.dirname (path.js:1121:5)
    at fromProjectRoot (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:13:18)
    at hasProjectFile (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/file.js:16:14)
    at hasPrettierConfig (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/utils/config.js:35:2)
    at Object.<anonymous> (/Users/Dominik/Desktop/project/sub-project/node_modules/@wordpress/scripts/config/.eslintrc.js:20:8)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
(node:52624) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:52624) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
2020-02-14T10:43:54.941Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:43:54.941Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:43:54.941Z eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/Users/Dominik/Desktop/project', loose: false } ]
2020-02-14T10:43:54.942Z eslint:ignore-pattern   processed: { basePath: '/Users/Dominik/Desktop/project', patterns: [ '/node_modules/*', '/bower_components/*' ] }
2020-02-14T10:43:54.942Z eslint:cascading-config-array-factory Load config files for /Users/Dominik/Desktop/project/sub-project.
2020-02-14T10:43:54.942Z eslint:cascading-config-array-factory No cache found: /Users/Dominik/Desktop/project/sub-project.
2020-02-14T10:43:54.942Z eslint:config-array-factory Loading JS config file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
2020-02-14T10:43:54.942Z eslint:config-array-factory Error reading JavaScript file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js
[Info  - 11:43:54] Cannot read config file: /Users/Dominik/Desktop/project/sub-project/.eslintrc.js Error: The "path" argument must be of type string. Received type undefined
@ocean90 ocean90 added [Type] Bug An existing feature does not function as intended [Tool] WP Scripts /packages/scripts labels Feb 14, 2020
@ocean90
Copy link
Member Author

ocean90 commented Feb 14, 2020

Can't tell yet if this is really a bug in the package itself or rather something with https://www.npmjs.com/package/read-pkg-up or even VS Code.
I wasn't able to trigger this error with Sublime Text for example.

@gziolo gziolo added the Needs Testing Needs further testing to be confirmed. label Mar 8, 2020
@gziolo
Copy link
Member

gziolo commented Apr 20, 2020

Would it make any difference if it would be imported as follows:

const defaultConfig = require('@wordpress/scripts/config/.eslintrc.js' );

???

Is it still an issue?

@ocean90
Copy link
Member Author

ocean90 commented Apr 20, 2020

No, I tried that as well and there's no difference.

I tried this again the other day and it's still not working. Though, it was a different error message iirc. I'll check it again to get the exact message.

@ocean90
Copy link
Member Author

ocean90 commented May 30, 2020

It seems like something in ESLint 7 has been changed which has also fixed this issue. #20235 updates the ESLint version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Testing Needs further testing to be confirmed. [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants