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

[Error] Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser #954

Closed
six-ponies opened this issue Apr 20, 2020 · 4 comments
Labels
info-needed Issue requires more information from poster

Comments

@six-ponies
Copy link

six-ponies commented Apr 20, 2020

Hi~ I found an error descibed above, and my versions are listed below:

package version
vscode-eslint 2.1.5
@typescript-eslint/parser 2.27.0
TypeScript 3.7.2
ESLint 6.8.0
vscode 1.44.1
Node.js 12.8.1
V8 7.8.279.23-electron.0
OS Linux x64 4.13.0-36-generic

eslint configs:

module.exports = {
    parser: '@typescript-eslint/parser',
    parserOptions: {
        warnOnUnsupportedTypeScriptVersion: false,
        ecmaVersion: 6,
        sourceType: 'module',
        project: 'tsconfig.json',
    }
}

This error happens when I use symlink as my workspace dir, e.g.
/home/xxx/workspace/ -> /workspace

I tried to div into source code and found languageServer use symlink uri when file changed, e.g.
/home/xxx/workspace/src/index.js
but typescript-estree use extra.tsconfigRootDir = '/workspace' to createProjectProgram.

I also found a way to solve this problem:

function getFileSystemPath(uri: URI): string {
	const result = uri.fsPath;
	if (process.platform === 'win32' && result.length >= 2 && result[1] === ':') {
		// Node by default uses an upper case drive letter and ESLint uses
		// === to compare paths which results in the equal check failing
		// if the drive letter is lower case in th URI. Ensure upper case.
		return result[0].toUpperCase() + result.substr(1);
	} else {
		return fs.realpathSync(result); // I added fs.realpathSync to solve this problem
	}
}

Let me know if this solution is correct, thank you

@six-ponies six-ponies changed the title [] [Error] Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser Apr 20, 2020
@dbaeumer
Copy link
Member

Actually I am not a fan of blindly making this change since it will affect quite some other code passes as well. Can you please elaborate what you think is the root cause of this and why the typescript-eslint/parser complain about it with a parsing error. This is absolutely not clear to me.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Apr 21, 2020
@six-ponies
Copy link
Author

six-ponies commented Apr 21, 2020

This error happend at @typescript-eslint/typescript-estree/src/createProjectProgram.ts line 35
image

extra = {
    tsconfigRootDir: '/workspace', // tsconfigRootDir is initialized by process.cwd() which returns realpath not symlink
    filePath: '/home/xxx/workspace/src/index.ts' // in this case, filePath is initialized by vscode-eslint/eslintServer.ts
   // ignore other properties
}

typescript-estree uses 'extra' opotions to init typescript program, typescript program reads all files defined by our '/workspace/tsconfig.json' based on tsconfigRootDir and stores as a Map which key is the filename start with '/workspace' not '/home/xxx/workspace'.
so currentProgram.getSourceFile(extra.filePath) returns undefined

@dbaeumer
Copy link
Member

@Lordisback is this still an issue for you. If so can you please provide me with a GitHub repository I can clone that demos what you are experiencing.

@vscodebot vscodebot bot closed this as completed Oct 30, 2020
@vscodebot
Copy link

vscodebot bot commented Oct 30, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants