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

Working with tslint-loader #15

Open
morriq opened this issue Oct 31, 2017 · 7 comments · May be fixed by #78
Open

Working with tslint-loader #15

morriq opened this issue Oct 31, 2017 · 7 comments · May be fixed by #78

Comments

@morriq
Copy link

morriq commented Oct 31, 2017

Hello, since I'm using tslint-loader I have issue with tsconfig-paths.

My problem is that tslint-loader try to load tslint using
var Lint = require('tslint');
https://github.com/wbuchwalter/tslint-loader/blob/4d166651d916a0c43dd5a11099d6ff532350e27b/index.js#L8

but same file exists in my project so while tslint-loader try to load tslint from node_modules then it's receiving tslint from my project.

Would somebody help me please?

@Jontem
Copy link
Member

Jontem commented Sep 2, 2018

Sorry for the late response. Is this still a problem? Maybe we could implement an option for specifying excluded modules names that should not be resolved with tsconfig-paths

@mihkeleidast
Copy link

As far as I know, this is still a problem. A workaround I have used is setting "baseUrl": "./src", in my tsconfig, that way it does not try to resolve files in root.

@stenin-nikita
Copy link

In my opinion, this implementation is more correct and also solves the problem above

  Module._resolveFilename = function(request: string, _parent: any): string {
    try {
      // tslint:disable-next-line:no-invalid-this
      return originalResolveFilename.apply(this, arguments);
    } catch (err) {
      const found = matchPath(request);
      if (found) {
        const modifiedArguments = [found, ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above.
        // tslint:disable-next-line:no-invalid-this
        return originalResolveFilename.apply(this, modifiedArguments);
      }

      throw err;
    }
  };

stenin-nikita pushed a commit to stenin-nikita/tsconfig-paths that referenced this issue Nov 3, 2018
@jonaskello
Copy link
Member

Just to clarify let me see if I understand how to re-create the problem:

  • Use tslint-loader with webpack.
  • Have a tslint.json file in the root of the project.
  • Start webpack somehow with tsconfig-paths registered.

Is that correct?

Also, iIf someone would like to provide a repo which reproduces the problem that would also save us some time to try and re-create it.

@stenin-nikita
Copy link

I recreated the problem in the sandbox. You need to download the project and run npm install and npm start. https://codesandbox.io/s/7klz2y4v30

@stenin-nikita
Copy link

I think my solution will not cause performance problems. It may be worth checking the type of error. For example:

    try {
      // tslint:disable-next-line:no-invalid-this
      return originalResolveFilename.apply(this, arguments);
    } catch (err) {
      if (err.code === 'MODULE_NOT_FOUND') {
        const found = matchPath(request);
        if (found) {
          const modifiedArguments = [found, ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above.
          // tslint:disable-next-line:no-invalid-this
          return originalResolveFilename.apply(this, modifiedArguments);
        }
      }
      throw err;
    }

@Athorcis
Copy link

what about adding an option disabled by default to enabled this behavior ?

@Athorcis Athorcis linked a pull request Mar 21, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants