Skip to content

typescript@next (and 2.9.x) outputs node_modules relative path to imports #25345

Closed

Description

@felixknox

Related to issue #24599 , where Mohamed Hegazy (@mhegazy) specifically asks to create a separate ticket with more information when using latest typescript@next (^3.0.0-dev.20180630")

Imports get's node_modules added, which breaks Library conventions.

It's easy to replicate.
import ex. a library like Material-UI (@material-ui), which you have as a dependency.

Using a tsconfig file like

"compilerOptions": {
    "baseUrl": "./",
    "rootDir": "src",
    "outDir": "dist",

    "declaration": true,

    "module": "commonjs",
    "target": "es5",
    "lib": [ "es6", "dom" ],
    "sourceMap": true,
    "moduleResolution": "node",

    "jsx": "react",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": false,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": false,
  },
  "exclude": [
    "node_modules"
  ]

Will take a .tsx file like:

import * as React from 'react';
import { WithStyles } from '@material-ui/core';
import { withStyles } from '@material-ui/core/styles';
import formBasicsStyles from "./../../../theme/formBasics";

interface IFileUploadProps extends WithStyles{

}

export const FileUpload = withStyles(formBasicsStyles)(
    class extends React.Component<IFileUploadProps> {
        constructor(props: IFileUploadProps){
            super(props);
        }

        public render() {
            const { classes } = this.props;

            return (
                <div>

                </div>
            );
        }
    }
);

And output a d.ts file like:

import * as React from 'react';
import { WithStyles } from '@material-ui/core';
interface IFileUploadProps extends WithStyles {
}
export declare const FileUpload: React.ComponentType<import("node_modules/@material-ui/core").Overwrite<IFileUploadProps, import("node_modules/@material-ui/core/styles/withStyles").StyledComponentProps<string>>>;
export {};

In the output d.ts file one would
expect: import("@material-ui....
but result is: import("node_modules/@material-ui...

Hope information is sufficient.

Activity

  1. changed the title [-]typescript@next (and 2.9.x) outputs node_modules relate path to imports[/-] [+]typescript@next (and 2.9.x) outputs node_modules relative path to imports[/+] on Jun 30, 2018
  2. Kingwl commented on Jul 1, 2018

    @Kingwl
    Contributor
  3. mhegazy commented on Jul 2, 2018

    @mhegazy
    Contributor

    looks like a possible duplicate of #25338

  4. weswigham commented on Jul 2, 2018

    @weswigham
    Member

    Mohamed Hegazy (@mhegazy) I'd wager it's much more likely another expression of #25186. (which Andy (Andrewkraft) (@Andy-MS) has a fix open for)

  5. ghost added
    Needs More InfoThe issue still hasn't been fully clarified
    on Jul 3, 2018
  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptNeeds More InfoThe issue still hasn't been fully clarified

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions