Skip to content

Fix issue with TypeScript paths with allowJs - #470

Merged
styfle merged 4 commits into
vercel:masterfrom
novascreen:ts-allowjs-absolute-import
Sep 9, 2019
Merged

Fix issue with TypeScript paths with allowJs#470
styfle merged 4 commits into
vercel:masterfrom
novascreen:ts-allowjs-absolute-import

Conversation

@novascreen

Copy link
Copy Markdown
Contributor

Closes #469

I noticed something when I added the test, when you run the existing output.js of tsconfig-paths you also get "Cannot find module", not sure if the output there is intended to be different from output-coverage.js, but thought i'd point it out.

The tsconfig-paths-allowjs/output-coverage.js shows the difference between adding js to the extensions of TsconfigPathsPlugin and not having it.

@novascreen

Copy link
Copy Markdown
Contributor Author

Another thing, I wasn't sure whether i should only add js or make extensions be SUPPORTED_EXTENSIONS, let me know if i should change that.

@codecov-io

codecov-io commented Aug 31, 2019

Copy link
Copy Markdown

Codecov Report

Merging #470 into master will increase coverage by 0.25%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #470      +/-   ##
==========================================
+ Coverage   74.68%   74.93%   +0.25%     
==========================================
  Files          13       13              
  Lines         395      399       +4     
==========================================
+ Hits          295      299       +4     
  Misses        100      100
Impacted Files Coverage Δ
src/index.js 83.92% <100%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2081579...9cd8306. Read the comment docs.

Comment thread src/index.js Outdated
// error if there's no tsconfig in the working directory
try {
resolvePlugins.push(new TsconfigPathsPlugin({ silent: true }));
resolvePlugins.push(new TsconfigPathsPlugin({ silent: true, extensions: [".ts", ".tsx", ".js"] }));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resolvePlugins.push(new TsconfigPathsPlugin({ silent: true, extensions: [".ts", ".tsx", ".js"] }));
resolvePlugins.push(new TsconfigPathsPlugin({ silent: true, extensions: SUPPORTED_EXTENSIONS }));

The docs mention that these should be the same.

Perhaps this should look for allowJs option before assigning the extensions.

If you're using allowJs in tsconfig.json, or allow other non-TS extensions in webpack, make sure you set extensions option in sync with your webpack config.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@styfle I believe I addressed both your suggestions, I did it in two steps, let me know if you want to keep the check against the tsconfig.json

@novascreen
novascreen force-pushed the ts-allowjs-absolute-import branch from 3e37e30 to 9cd8306 Compare September 5, 2019 17:18
@styfle styfle changed the title Fix issue with TypeScript paths and allowjs Fix issue with TypeScript paths with allowJs Sep 9, 2019

@styfle styfle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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 this pull request may close these issues.

TypeScript with allowJS and absolute imports fails at runtime

4 participants