Skip to content

Don't exclude node_modules by default #18884

@jez9999

Description

@jez9999

There is a perfectly good use-case for transpiling a node_modules directory. As far as I can tell, it's the only way you can include your own ES6 modules without using relative paths, which can be messy and hard to maintain. So you setup a directory structure like this:

src /
    node_modules /
        modules /
            myModule.ts
    scripts /
        init.ts

And you want it to be transpiled by TypeScript into this:

dist /
    node_modules /
        modules /
            myModule.js
    scripts /
        init.js

This then allows you to refer to your module from any code under src (such as init.js) using:

import myModule from "modules/myModule";

... rather than having to use a relative path. Because TypeScript and Node.js go up the directory tree looking for node_modules directories, they will find this one before the main NPM one, which should be at least a directory higher, in the project's root directory.

However, this all requires that TypeScript not ignore the node_modules directory that we've created in src. Considering that developers will probably tell TypeScript to transpile stuff in a src directory anyway, it won't include the main NPM node_modules so I suggest that node_modules shouldn't be excluded by default, which would allow this scenario to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions