question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin producing `*.d.ts` with in-line imports

See original GitHub issue

What happens and why it is wrong

rollup-plugin-typescript2 is generating *.d.ts file that is not valid TypeScript:

export declare function deferredAction<T extends StdOut>(saga: Saga<T, Action>, io: T): (action: DeferredAction) => IterableIterator<SetContextEffect<any> | etc..| import("../node_modules/redux-saga/effects").Effect[]>;

Notice the import("../node_modules/redux-saga/effects").Effect[] that is trying to be used as a type parameter.

I’ve run tsc directly, which behaves as expected (aside from dumping all the built files in the wrong spot).

This is for a library I’m working on, so the source (and the branch) is here

Environment

Versions

  • typescript: ^2.9.1
  • rollup: ^0.59.4
  • rollup-plugin-typescript2: ^0.14.0

rollup.config.js

import typescript from 'rollup-plugin-typescript2'

const baseConfig = {
  plugins: [ typescript() ],

  input: 'src/index.ts',

  external: [
    'redux',
    'redux-saga',
    'redux-saga/effects'
  ]
}

const esConfig = Object.assign(
  {},
  baseConfig,
  {
    output: {
      exports: 'named',
      file: 'dist/es/index.js',
      format: 'es'
    }
  }
)

const cjsConfig = Object.assign(
  {},
  baseConfig,
  {
    output: {
      exports: 'named',
      file: 'dist/cjs/index.js',
      format: 'cjs'
    }
  }
)

export default [
  cjsConfig,
  esConfig
]

tsconfig.json

{
  "exclude": [
    "**/*.test.ts",
    "node_modules"
  ],

  "include": [ "src/**/*.ts" ],

  "compilerOptions": {
    "baseUrl": "./",
    "declaration": true,
    "downlevelIteration": true,
    "jsx": "react",
    "module": "esnext",
    "moduleResolution": "node",
    "noUnusedParameters": true,
    "removeComments": false,
    "sourceMap": true,
    "strict": true,
    "target": "es5",

    "lib": [
      "dom",
      "esnext"
    ],

    "paths": {
      "@/*": ["src/*"]
    },

    "plugins": [
      { "name": "tslint-language-service"}
    ]
  }
}

package.json

{
  "scripts": { "build": "rm -rf dist && npx rollup -c" }
}

plugin output with verbosity 3

I don’t see anything that looks relevant, though I can amend this.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
killtheliteratecommented, Jun 8, 2018

@ezolenko took your advice and ran ./node_modules/.bin/tsc, which does reproduce the problem—hmm, something got weird in TypeScript 2.9.1 — the global tsc is 2.8.1.

I factored out those typings, as they were kind of borked, but still weird.

1reaction
ezolenkocommented, Jun 6, 2018

And check that you use the same typescript version when running tsc as when using rollup or webpack plugins (global vs local install)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Somtimes generating inline imports for d.ts files instead of ...
Problem statement: The d.ts file generated during my compile step looks like this: export declare const authContentFeatureReducer ...
Read more >
Import class in definition file (*d.ts) - typescript - Stack Overflow
d.ts files are treated as an ambient module declarations only if they ... are not declaring a module, you can import inline at...
Read more >
Cannot find module" when using inline webpack loaders with ...
Trying to use a webpack raw-loader for an HTML file inline resulted in an error: TS2307: Cannot find module. Here's how to fix...
Read more >
TSConfig Reference - Docs on every TSConfig option
Allows importing modules with a '.json' extension, which is a common practice in node projects. This includes generating a type for the import...
Read more >
Features | Vite
You can also use the query option to provide custom queries to imports for other plugins to consume. ts const modules = import.meta ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found