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

Typescript Support: Don't force consumers to enable esModuleInterop in tsconfig #110

Closed
ozyman42 opened this issue Aug 25, 2020 · 3 comments

Comments

@ozyman42
Copy link
Contributor

Because of this line it means that any project which consumes schema-utils either as a direct or transitive dependency must use the esModuleInterop tsconfig.json compilerOptions setting in order to compile their typescript.

Ideally we should not be forcing typescript users to add this setting if they don't want it. It also isnt necessary since in

Here's a demo:

  1. git clone https://github.com/AlexLeung/webpack-schema-utils-ajv-typescript-error-demo
  2. npm install
  3. npm start

You will see the following output, including a tsc error

> @ start /home/alex/GitProjects/experiments/webpack-schema-utils-ajv-typescript-error-demo                                                                                                                                                                                               
> tsc                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                          
node_modules/schema-utils/declarations/validate.d.ts:43:8 - error TS1259: Module '"/home/alex/GitProjects/experiments/webpack-schema-utils-ajv-typescript-error-demo/node_modules/ajv/lib/ajv"' can only be default-imported using the 'esModuleInterop' flag                             
                                                                                                                                                                                                                                                                                          
43 import Ajv from 'ajv';                                                                                                                                                                                                                                                                 
          ~~~                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                          
  node_modules/ajv/lib/ajv.d.ts:396:1                                                                                                                                                                                                                                                     
    396 export = ajv;                                                                                                                                                                                                                                                                     
        ~~~~~~~~~~~~~                                                                                                                                                                                                                                                                     
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.                                                                                                                                                      
                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                          
Found 1 error.                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                          
npm ERR! code ELIFECYCLE                                                                                                                                                                                                                                                                  
npm ERR! errno 2                                                                                                                                                                                                                                                                          
npm ERR! @ start: `tsc`                                                                                                                                                                                                                                                                   
npm ERR! Exit status 2                                                                                                                                                                                                                                                                    
npm ERR!                                                                                                                                                                                                                                                                                  
npm ERR! Failed at the @ start 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!     /home/alex/.npm/_logs/2020-08-25T08_10_43_693Z-debug.log      
  1. To fix you can navigate to ./node_modules/schema-utils/declarations/validate.d.ts then change line 43 from
import Ajv from 'ajv';

to

import * as Ajv from 'ajv';
  1. Run npm start again and now the compilation succeeds.

The change described in step 4 is fine because we are only exporting types from the ajv package.
I'll submit a PR for this shortly.

@alexander-akait
Copy link
Member

Feel free to send a PR

@ozyman42
Copy link
Contributor Author

sent

@alexander-akait
Copy link
Member

Fixed

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

No branches or pull requests

2 participants