Skip to content

jsconfig default settings for module type is inconsistent #6690

Closed

Description

@egamma

No jsconfig.json in the workspace
Then the module type defaults to none

jsconfig.json exists but no module property defined
Then the module type defaults to commonjs

Suggest that the module type default is always the same independent of whether there is a jsconfig.json.

If the module property is commonjs by default then I suggest that there is also a default for exclude containing the node_modules folder.

Activity

  1. mhegazy commented on Jan 28, 2016

    @mhegazy
    Contributor

    the problem here was you will get an error:

    error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.

    which most ppl have found annoying int he past. given that JS users would probably have a transpiler already, do we want to show them that error?

  2. zhengbli commented on Jan 28, 2016

    @zhengbli

    Mohamed Hegazy (@mhegazy) Does't the default module option also impact how we resolve modules for js files? Even without the error message

  3. egamma commented on Jan 28, 2016

    @egamma
    MemberAuthor

    Mohamed Hegazy (@mhegazy) the error message is unpleasant since I don't think of code generation when I use JS only. However, given your argument, shouldn't then the default also be commonjs when there is no jsconfig.json?

  4. mhegazy commented on Jan 28, 2016

    @mhegazy
    Contributor

    that is correct, but for that we could set the "moduleResolution" flag, but the error still stays.

  5. mhegazy commented on Jan 28, 2016

    @mhegazy
    Contributor

    shouldn't then the default also be commonjs when there is no jsconfig.json?

    in retrospect, yes :) but this would be a big breaking change.

  6. billti commented on Jan 28, 2016

    @billti
    Member

    I sent an email on this couple mins ago... repeating below

    We chose the current behavior as without a ‘module’ setting the TypeScript engine gives you errors on import/export statements that no module type is defined. With an ES3/ES5 emit target (the default and most common settings), we need to know how to treat these (e.g. as CommonJS, AMD, or System modules). With JavaScript also (optionally) being transpiled now, the same problem exists.

    We initially did have a default other than ‘none’, but found too many users were trying to use modules without understand them and the need for a runtime that supported them, so we wanted to add a little impedance to make them stop and think “what module type are trying to use”, and maybe look at some docs if not sure.

    Some of the user confusion was caused by TypeScript overloading the “module” keyword for both internal & external modules. Now we’ve moved to “namespace” for internal modules, this should be lessened. Also, Node development being more prevelant, and with CommonJS also being commonly the format of choice in the browser (via browserify, WebPack, etc.), perhaps we could consider defaulting to CommonJS again. Thus ES6 import/export syntax just works, and would emit CommonJS by default, if there is no “module” setting provided.

  7. mhegazy commented on Jan 28, 2016

    @mhegazy
    Contributor

    in retrospect, yes :) but this would be a big breaking change.

    correction for my original statement, that would not be a breaking change, existing projects should not be affected. it would be a surprising change though to existing users of TS.

    We should consider this for the design meeting tomorrow.

  8. added and removed
    BugA bug in TypeScript
    on Jan 28, 2016
  9. mhegazy commented on Jan 29, 2016

    @mhegazy
    Contributor

    Conclusion is to move to CommonJs as the default module kind

  10. egamma commented on Feb 1, 2016

    @egamma
    MemberAuthor

    a good outcome, thanks.

    Should this also be assigned to the Salsa 0.9 milestone?

  11. mhegazy commented on Feb 2, 2016

    @mhegazy
    Contributor

    closing in favor of #6807

  12. added
    DuplicateAn existing issue was already created
    and removed
    CommittedThe team has roadmapped this issue
    on Feb 2, 2016
  13. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions