GithubHelp home page GithubHelp logo

ezolenko / rollup-plugin-typescript2 Goto Github PK

View Code? Open in Web Editor NEW
815.0 815.0 70.0 8.79 MB

Rollup plugin for typescript with compiler errors.

License: MIT License

JavaScript 3.58% TypeScript 96.42%
rollup rollup-plugin rollup-plugin-typescript rollup-plugin-typescript2 typescript

rollup-plugin-typescript2's People

Contributors

agilgur5 avatar ajlende avatar andarist avatar antross avatar bluelovers avatar bluetech avatar brandon-leapyear avatar chocolateboy avatar cslecours avatar cuyl avatar dependabot[bot] avatar domoritz avatar equalma avatar ezolenko avatar ezolenko2 avatar frankwallis avatar houfio avatar lmk123 avatar marijnh avatar mattdsteele avatar mesqueeb avatar nickmccurdy avatar nicolasthierion avatar notwoods avatar ooflorent avatar rossipedia avatar sorrycc avatar warrenseine avatar wessberg avatar xaviergonz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rollup-plugin-typescript2's Issues

`Cannot call a namespace` error with rpt2 but not `tsc`

What happens and why it is wrong

When I run tsc -p . on my project, everything compiles as expected, but when I use rollup and rollup-plugin-typescript2 with minimal config, it gives me a TypeScript error. I am using the same TypeScript version in both cases as revealed by using tsc -v at the terminal and also checking with verbosity: 3.

You can see a repro here.

Please note that I am using a fork of Rollup in there which fixed a sourcemap issue that actually allows me to see the underlying TypeScript problem.

The TypeScript error is just a random error with the qrcode-generator NPM package, it says Cannot call a namespace, but the usage should be fine.

Environment

  • Windows 10
  • Rollup fork, see above

Versions

  • typescript: tsc -v = Version 2.7.2 but I also have a dev dependency on TypeScript 2.7.2
  • rollup: adrianheine/rollup#sourcemap see above
  • rollup-plugin-typescript2: 0.11.1

rollup.config.js

import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';

export default {
  input: 'index.ts',
  output: {
    file: 'bundle.js',
    format: 'iife'
  },
  plugins: [
    resolve(),
    typescript()
  ]
};

tsconfig.json

{
  "compilerOptions": {
    
  }
}

package.json

{
  "name": "rollup",
  "version": "1.0.0",
  "main": "bundle.js",
  "repository": "https://gitlab.com/TomasHubelbauer/bloggo-rollup.git",
  "author": "Tomáš Hübelbauer <[email protected]>",
  "license": "MIT",
  "scripts": {
    "start": "node node_modules/rollup/bin/rollup -c"
  },
  "devDependencies": {
    "rollup": "adrianheine/rollup#sourcemap",
    "rollup-plugin-node-resolve": "^3.0.3",
    "rollup-plugin-typescript2": "^0.11.1",
    "tslint": "^5.9.1",
    "typescript": "^2.7.2"
  },
  "dependencies": {
    "jsqr": "^1.0.2",
    "qrcode-generator": "^1.3.1"
  }
}

plugin output with verbosity 3

rpt2: typescript version: 2.7.2
rpt2: rollup-plugin-typescript2 version: 0.11.1
rpt2: plugin options:
{
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "C:\\Users\\Tom\\Desktop\\bloggo-rollup/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "typescript": "version 2.7.2",
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "tsconfigDefaults": {}
}
rpt2: rollup config:
{
    "input": "index.ts",
    "plugins": [
        {
            "name": "node-resolve"
        },
        {
            "name": "rpt2"
        }
    ],
    "entry": "index.ts",
    "external": [
        "",
        ""
    ]
}
rpt2: built-in options overrides: {
    "module": 5,
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "outDir": "C:\\Users\\Tom\\Desktop\\bloggo-rollup",
    "moduleResolution": 2,
    "declarationDir": null
}
rpt2: parsed tsconfig: {
    "options": {
        "module": 5,
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "outDir": "C:\\Users\\Tom\\Desktop\\bloggo-rollup",
        "moduleResolution": 2,
        "declarationDir": null,
        "configFilePath": "C:\\Users\\Tom\\Desktop\\bloggo-rollup/tsconfig.json"
    },
    "fileNames": [
        "C:/Users/Tom/Desktop/bloggo-rollup/index.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {}
    },
    "errors": [],
    "wildcardDirectories": {
        "c:/users/tom/desktop/bloggo-rollup": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "**/*"
        ],
        "validatedIncludeSpecs": [
            "**/*"
        ],
        "wildcardDirectories": {
            "c:/users/tom/desktop/bloggo-rollup": 1
        }
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: Ambient types:
rpt2: transpiling 'C:\Users\Tom\Desktop\bloggo-rollup\index.ts'
rpt2:     cache: 'C:\Users\Tom\Desktop\bloggo-rollup/.rpt2_cache/22ff6e2bd8b463bdcea5bf8a6a76797d32066ea4/code/cache/f4e451f1a8985ff1269065353acafb08210b840d'
rpt2:     cache miss
rpt2:     cache: 'C:\Users\Tom\Desktop\bloggo-rollup/.rpt2_cache/22ff6e2bd8b463bdcea5bf8a6a76797d32066ea4/syntacticDiagnostics/cache/f4e451f1a8985ff1269065353acafb08210b840d'
rpt2:     cache miss
rpt2:     cache: 'C:\Users\Tom\Desktop\bloggo-rollup/.rpt2_cache/22ff6e2bd8b463bdcea5bf8a6a76797d32066ea4/semanticDiagnostics/cache/f4e451f1a8985ff1269065353acafb08210b840d'
rpt2:     cache miss
[!] Error: Cannot call a namespace ('qrcode')
index.ts (2:9)
1: import * as jsqr from 'jsqr';
2: import * as qrcode from 'qrcode-generator';
            ^
3:
4: const qr = qrcode(0, 'H');

error Command failed with exit code 1.

Error `TS5052` when `declarationDir` is set, but `declaration: false` override

What happens and why it is wrong

Typescript compile option doesn't allow set declaration: false and declarationDir at same time.

options error TS5052 Option 'declarationDir' cannot be specified without specifying option 'declaration'.

But according to microsoft/TypeScript#14184, setting with declarationDir: null and declaration: false is able to cancel emitting type files.

Unfortunately, after setting override declarationDir: null, declaration: false and useTsconfigDeclarationDir:false, in lvl 3 verbosity, terminal reports that declarationDir in parsed tsconfig is current project path. The expected declarationDir should be null.

Environment

Versions

  • typescript: 2.6.2
  • rollup: 0.55.1
  • rollup-plugin-typescript2: 0.10.0

rollup.config.js

import typescript from 'rollup-plugin-typescript2'
import camelCase from 'camel-case'

const pkg = require('./package.json')

export default {
  input: 'src/index.ts',
  output: {
    file: pkg.main,
    format: 'umd',
    name: camelCase(pkg.name),
  },
  watch: {
    include: 'src/**',
  },
  plugins: [
    typescript({
      verbosity: 3,
      tsconfigOverride: {
        compilerOptions: {
          target: 'es5',
          declaration: false,
          declarationDir: null,
        },
      },
      useTsconfigDeclarationDir: true,
    }),
  ],
}

tsconfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "target": "es6",
    "lib": ["es6", "es7", "es2017", "dom"],
    "moduleResolution": "node",
    "declarationDir": "dist/types",
    "declaration": true,
    "allowSyntheticDefaultImports": true,
  },
  "include": [
    "src/*"
  ]
}

Same cache dir between multiple projects errors with parallel usage

My build system creates 3 bundles with rollup. If I build each bundle serially, it succeeds. However, if I build them concurrently (e.g. with make -j4, gulp, ...), it fails like this:

[19:54:40] Using gulpfile client/gulpfile.js
[19:54:40] Starting 'scripts.foo'...
[19:54:42] Starting 'scripts.bar'...
[19:54:44] Starting 'scripts.baz'...
Error: ENOENT: no such file or directory, open 'client/.rpt2_cache/c96394021b516827cdd67f325bc8e31a9c85a68e/code/cache_/c25c849c2122f988238ef5fb3159bccdcf3167ca'
    at error (client/node_modules/rollup/dist/rollup.js:170:12)
    at client/node_modules/rollup/dist/rollup.js:8926:6
    at process._tickCallback (internal/process/next_tick.js:109:7)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:423:7)
    at startup (bootstrap_node.js:147:9)
    at bootstrap_node.js:538:3
Error: ENOENT: no such file or directory, open 'client/.rpt2_cache/c96394021b516827cdd67f325bc8e31a9c85a68e/code/cache_/fe9b01c7ea2aa0c98e1433b824f39491fdead469'
    at error (client/node_modules/rollup/dist/rollup.js:170:12)
    at client/node_modules/rollup/dist/rollup.js:8926:6
    at process._tickCallback (internal/process/next_tick.js:109:7)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:423:7)
    at startup (bootstrap_node.js:147:9)
    at bootstrap_node.js:538:3
[19:54:49] Finished 'scripts.bar' after 6.27 s
[19:54:49] Finished 'scripts.foo' after 8.97 s
[19:54:49] Finished 'scripts.baz' after 5.65 s
[19:54:49] Starting 'scripts'...
[19:54:49] Finished 'scripts' after 67 μs

I can try to provide a reproducer, if needed.

These are the relevant package versions:

$ npm ls --depth=0
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Thanks.

Why are interface declarations removed?

Hi,

I'm trying to move from webpack to rollup for a library and I have trouble getting declarations to work correctly.

It seems that interfaces declarations aren't exported, this is a problem when I have things like :

import { RenderedCell } from "../RenderedCell";

export default class MergedCell implements RenderedCell {
    // ...
}

I get the error that RenderedCell can't be found.
I worked in webpack, and I can't understand what's the difference in my configuration that broke this. but I seem to understand that it's normal with Rollup.

BTW. I'm using the latest rollup, rollup-plugin-typescript2 and rollup-plugin-uglify I can post my configurations if needed

support for `pretty: true`?

@ezolenko when my tsconfig has pretty: true, I can see

$ tsc

src/About/About.js(22,9): error TS1136: Property assignment expected.

22         ;doh
           ~

just curious if this plugin can report that too? Fair enough it does give the row,column info like this:

[!] (rpt2 plugin) Error: ...path.../src/About/About.js (22,9): syntax error TS1136 Property assignment expected.
src/About/About.js

But it would be super awesome to show what tsc shows for the context. I tried adjusting the verbosity but that did not seem to do it.

definition files are not generated -- can't repro

I could not generate *.d.ts files using rollup-plugin-typescript2. I set declaration flag to true in tsconfig.json. The documentation of plugin says it must work however it did not.

{
    "compilerOptions": {
        "typeRoots": ["node_modules/@types"],
        "types": ["jquery", "angular", "lodash", "jasmine", "angular-mocks"],
        "allowUnreachableCode": false,
        "allowUnusedLabels": false,
        "baseUrl": "./src",
        "forceConsistentCasingInFileNames": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "preserveConstEnums": false,
        "target": "es5",
        "sourceMap": false,
        "declaration": true
    },
    "include": [
        "src/module.ts",
        "src/**/*.ts"
    ],
    "exclude": [
        "src/test/*.ts"
    ]
}

Any help would be much appreciated

Cannot find module 'typescript' -- need to install TS

import typescript from 'rollup-plugin-typescript2';

-node_modules
-src
--main.js
--....
-rollup.config.js
-tsconfig.json
-package.json

Error: Cannot find module 'typescript'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at typescript (...\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:19760:21)
    at Object.<anonymous> (...\rollup.config.js:17:7)
    at Module._compile (module.js:571:32)
    at Object.require.extensions..js (...\node_modules\rollup\bin\rollup:20371:8)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
"rollup": "^0.52.1",
"rollup-plugin-json": "^2.3.0",
"rollup-plugin-typescript2": "^0.8.4"

build command: "build": "rollup -c"

No compiler errors compared to tsc

Hi,

I'm trying to use the plugin, however I'm getting no compiler errors at all when building with rollup, compared to running tsc.

Here's the output from tsc:

src/main/ts/core/api/track-event.ts(83,17): error TS2345: Argument of type 'string' is not assignable to parameter of type 'ZeptoEventHandlers'.
src/main/ts/core/content/renderers/helpers/renderer-helpers.ts(71,12): error TS2345: Argument of type '"load"' is not assignable to parameter of type 'ZeptoEventHandlers'.
src/main/ts/core/content/renderers/helpers/renderer-helpers.ts(77,12): error TS2345: Argument of type '"error"' is not assignable to parameter of type 'ZeptoEventHandlers'.
src/main/ts/core/content/renderers/set-attribute.ts(26,12): error TS2345: Argument of type '"load"' is not assignable to parameter of type 'ZeptoEventHandlers'.
src/main/ts/core/content/renderers/set-attribute.ts(31,12): error TS2345: Argument of type '"error"' is not assignable to parameter of type 'ZeptoEventHandlers'.
src/main/ts/foundation/zepto.ts(1621,14): error TS2322: Type '(selector: any, context: any) => any' is not assignable to type 'ZeptoStatic'.
  Property 'camelCase' is missing in type '(selector: any, context: any) => any'.

Here's my rollup config:

import typescript from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import path from 'path';
import license from 'rollup-plugin-license';
import cleanup from 'rollup-plugin-cleanup';

export default {
  entry: './src/main/ts/bootstrap.ts',

  format: 'iife',

  moduleName: 'testmodule',

  dest: './dist/out.js',

  sourceMap: false,

  plugins: [
    typescript({
      check: true,
      include: [ "*.ts+(|x)", "**/*.ts+(|x)" ]
	}),
    resolve({
      jsnext: true,
      main: true,
      browser: true
	}),
    commonjs({
      include: 'node_modules/**',
      exclude: [ 'node_modules/@types/**' ],
      extensions: [ '.js' ],
      ignoreGlobal: false,
      sourceMap: false,
      namedExports: {
        'node_modules/js-cookie/src/js.cookie.js': [ 'get', 'set', 'remove']
      }
    }),
    license({
      sourceMap: true,
      banner: {
        file: path.join(__dirname, 'tools/decorations/license.txt')
      }
    }),
    cleanup({
      comments: 'some'
    })
  ]
}

And tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es5",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": false,
    "removeComments": false,
    "noEmitHelpers": true,
    "sourceMap": false,
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "maxNodeModuleJsDepth": 1,
    "types" : [
      "es6-shim",
      "js-cookie",
      "query-string"
    ]
  },
  "include": [
    "**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

I'm using TypeScript v2.2.1

Large cache throws `Invalid string length` when stringifying config

On a watch, first compile is ok but then re-compiling after a change throws the following;

/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:19791
            context.debug("rollup config:\n" + JSON.stringify(rollupOptions, undefined, 4));
                                                    ^
RangeError: Invalid string length

The rollupOptions object is massive if I log it out:

  cache:
   { imports: [],
     exports: [ 'app' ],
     modules:
      [ [Object],
        [Object],
        ..... (removed for brevity)
        [Object],
        [Object],
        [Object],
        ... 1651 more items ],

Which seems to be whats throwing what is essentially an out of memory error from JSON.stringify

Commenting out the line to log out that and everything works fine. Just wondering whether I'm doing something wrong to result in such a large cache (it is a big project) or whether this is just a use case thats never manifested itself in 'regular' use.

Fails with complex usage scenario with `commonjs` and POSIX paths

Apologies for not breaking this down to a minimal reproduction case, but I don't have time right now and I thought you might be interested in the issue even without the full repro, and that you might understand what the fundamental issue is.

I have a pretty complex Rollup configuration:

module.exports = {
    entry: 'src/host/main.ts',
    dest: 'int/js/mainout.js',
    exports: "none",
    external: [
        "bluebird",
        "power-assert"
    ],
    globals: {
        "bluebird": "Promise",
        "power-assert": "assert"
    },
    useStrict: true,
    sourceMap: true,
    format: "iife",
    plugins: [
        json(),
        typescript({
            typescript: require('typescript'),
        }),
        nodeResolve({
            // use "jsnext:main" if possible
            // – see https://github.com/rollup/rollup/wiki/jsnext:main
            jsnext: true, // Default: false

            // use "main" field or index.js, even if it's not an ES6 module
            // (needs to be converted from CommonJS to ES6
            // – see https://github.com/rollup/rollup-plugin-commonjs
            main: true, // Default: true

            // if there's something your bundle requires that you DON'T
            // want to include, add it to 'skip'
            skip: [],  // Default: []

            // some package.json files have a `browser` field which
            // specifies alternative files to load for people bundling
            // for the browser. If that's you, use this option, otherwise
            // pkg.browser will be ignored
            browser: true, // Default: false

            // not all files you want to resolve are .js files
            extensions: [ '.js', '.json', '.ts' ], // Default: ['.js']
            sourceMap: true,

            // whether to prefer built-in modules (e.g. `fs`, `path`) or
            // local ones with the same names
            preferBuiltins: false // Default: true
        }),
        commonjs({
            extensions: [ '.js', '.ts' ],
            namedExports: {
                "javascript-astar": [ "Graph", "astar" ],
                "screenfull": [ "request" ],
                "marked": ["Renderer","setOptions","parse"],
            }
        }),
        buble({transforms: { dangerousForOf: true, dangerousTaggedTemplateString: true }})
    ]
};

This (mostly) works with the rollup-plugin-typescript plugin, but I thought I'd try this variant of the plugin instead. In part I wanted to try this because the last step above -- buble -- is not processing the TypeScript helpers injected by rollup-plugin-typescript. Since you're doing something different, I thought that issue might be solved by switching to this plugin.

But when I switch my include to rollup-plugin-typescript2, I get an error:

Failed to build client-js: Error: Module C:/Users/tim/projects/games/steel/node_modules/javascript-astar/astar.js does not export astar (imported by C:/Users/tim/projects/games/steel/src/common/pathhelper.ts)
    at Module.trace (C:\Users\tim\projects\games\steel\node_modules\rollup\dist\rollup.js:6432:29)
    at C:\Users\tim\projects\games\steel\node_modules\rollup\dist\rollup.js:6006:32
...

This doesn't even look like it's in your code, but it doesn't happen when I run the code through the older plugin, and I don't have the time to dig down to the root cause here, so I need to fall back on the older plugin. Looking at the TypeScript options you're setting:

noEmitHelpers: true,
importHelpers: true

... I thought one of these might be causing the problem, but no, when I set those it works using the old plugin. Not only that, but it fixes the problem I was having (because TypeScript is now using the imported helpers which buble correctly).

I have a TypeScript declaration file for javascript-astar, but honestly what it looks like is happening above is not a TypeScript bug but some kind of interaction problem between this plugin and the commonjs plugin (where I specify explicit exports for javascript-astar).

So if I were you and wanted to test this, I'd get an example together that imports some raw JavaScript using the node-resolve and commonjs plugins and see how rollup-plugin-typescript2 might be breaking commonjs.

Cannot import plugin with `ts-node`

I am using this in a gulp to compile using gulp-better-rollup when importing it uses the typings from dist and loads rollup-plugin-typescript2.cjs.js

However rollup does not export the default as default in cjs

Using

import typescript from "rollup-plugin-typescript2"

results in TypeError: rollup_plugin_typescript2_1.default is not a function.

To work around this I have had to import like this

import * as typescript from "rollup-plugin-typescript2"

Then cast as any to invoke.

plugins: [
        (typescript as any)()
]

Also the interface for the options does not match the documentation, as the typeings has the options object as required and all properties as required.

Declaration output not compatible with Rollup 0.48

If output declaration files are desired, this version of the plugin will not work with Rollup after 0.47.6. Version 0.47.6 of Rollup works, but future versions do not.

This is because the Rollup dest option was changed to output.file which this plugin does not read when determining the declaration file paths.

rollup/rollup#1479

The plugin code in index.ts needs to be changed from

onwrite({ dest }: IRollupOptions)
to

onwrite({ file: dest }: IRollupOptions)

then it should work. Or something similar to this.

Declaration files are not generated when using `gulp-rollup` (works with pure Rollup)

What happens and why it is wrong

Declaration files are not generated

Environment

Windows

Versions

  • typescript: 2.7.1
  • gulp-rollup: "2.16.2",
  • rollup-plugin-typescript2: 0.11.1

rollup.config.js

return gulp.src('./tmp/coe/core/*')
    .pipe(rollup({
      // any option supported by Rollup can be set here.
      input:'./tmp/coe/core/Hello.tsx',
     
      output: {         
        format: 'es',
        sourcemap: true    
      },
      plugins: [        
        typescript({            
            tsconfig: "./tmp/coe/core/tsconfig.json",
            verbosity: 3,
            cacheRoot: './build_cache',
            exclude:[''] 
        })
      ],
      external: ['react']
    }))
    .pipe(rename(`core.es5.js`))
    .pipe(gulp.dest('./dist/coe'));

tsconfig.json

{
    "compilerOptions": {
      "target": "es5",
      "module": "commonjs",
      "moduleResolution": "node",
      "strict": true,
      "jsx": "react",
      "declaration": true, 
      "declarationDir": "/type",
      "allowSyntheticDefaultImports": true,
    } 
  }

package.json

plugin output with verbosity 3

`rpt2: typescript version: 2.7.1
rpt2: rollup-plugin-typescript2 version: 0.11.1
rpt2: plugin options:
{
    "tsconfig": "./tmp/coe/core/tsconfig.json",
    "verbosity": 3,
    "cacheRoot": "./build_cache",
    "check": true,
    "clean": false,
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "typescript": "version 2.7.1",
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "tsconfigDefaults": {}
}
rpt2: rollup config:
{
    "input": "./tmp/coe/core/Hello.tsx",
    "plugins": [
        {
            "name": "rpt2"
        },
        {}
    ],
    "entry": "./tmp/coe/core/Hello.tsx",
    "external": [
        "react",
        ""
    ]
}
rpt2: built-in options overrides: {
    "module": 5,
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "outDir": "D:\\Users\\jaiky.m\\projects\\react-ts-app",
    "moduleResolution": 2,
    "declarationDir": "D:\\Users\\jaiky.m\\projects\\react-ts-app"
}
rpt2: parsed tsconfig: {
    "options": {
        "target": 1,
        "module": 5,
        "moduleResolution": 2,
        "strict": true,
        "jsx": 2,
        "declaration": true,
        "declarationDir": "D:\\Users\\jaiky.m\\projects\\react-ts-app",
        "allowSyntheticDefaultImports": true,
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "outDir": "D:\\Users\\jaiky.m\\projects\\react-ts-app",
        "configFilePath": "D:\\Users\\jaiky.m\\projects\\react-ts-app/./tmp/coe/core/tsconfig.json"
    },
    "fileNames": [
        "D:/Users/jaiky.m/projects/react-ts-app/tmp/coe/core/Hello.tsx"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "target": "es5",
            "module": "commonjs",
            "moduleResolution": "node",
            "strict": true,
            "jsx": "react",
            "declaration": true,
            "declarationDir": "/type",
            "allowSyntheticDefaultImports": true
        }
    },
    "errors": [],
    "wildcardDirectories": {
        "d:/users/jaiky.m/projects/react-ts-app/tmp/coe/core": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "**/*"
        ],
        "validatedIncludeSpecs": [
            "**/*"
        ],
        "wildcardDirectories": {
            "d:/users/jaiky.m/projects/react-ts-app/tmp/coe/core": 1
        }
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'

rpt2: Ambient types:
rpt2:     D:/Users/jaiky.m/projects/react-ts-app/node_modules/@types/jest/index.d.ts
rpt2:     D:/Users/jaiky.m/projects/react-ts-app/node_modules/@types/node/index.d.ts
rpt2:     D:/Users/jaiky.m/projects/react-ts-app/node_modules/@types/react/index.d.ts
rpt2:     D:/Users/jaiky.m/projects/react-ts-app/node_modules/@types/react-dom/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling 'D:/Users/jaiky.m/projects/react-ts-app/tmp/coe/core/Hello.tsx'
rpt2:     cache: './build_cache/1973214644ac08c1cbffed73421e01a943eaaeb7/code/cache/5b541c4cb2e26e07a884747c5fdaaac9e2eeeb69'
rpt2:     cache miss
rpt2:     cache: './build_cache/1973214644ac08c1cbffed73421e01a943eaaeb7/syntacticDiagnostics/cache/5b541c4cb2e26e07a884747c5fdaaac9e2eeeb69'
rpt2:     cache miss
rpt2:     cache: './build_cache/1973214644ac08c1cbffed73421e01a943eaaeb7/semanticDiagnostics/cache/5b541c4cb2e26e07a884747c5fdaaac9e2eeeb69'
rpt2:     cache miss
rpt2: generated declarations for 'D:/Users/jaiky.m/projects/react-ts-app/tmp/coe/core/Hello.tsx'
rpt2: generating target 1
rpt2: rolling caches
[16:32:19] Finished 'bundle' after 3.17 s
[16:32:19] Starting 'remove:cache'...
Deleted files and folders:
 D:\Users\jaiky.m\projects\react-ts-app\build_cache
[16:32:21] Finished 'remove:cache' after 2.03 s'

This is really slow (@alexlur’s repository is way faster with the same features)

A simple, unscientific test of putting TypeScript into an existing Rollup project (15KLOC, 30 including comments and blanks):

  • No TypeScript: 1.4 seconds;
  • @alexlur/rollup-plugin-typescript 1.0.4: 5.1 seconds;
  • rollup-plugin-typescript2 0.3.0 (this repository): roughly 16 seconds, or 6.5 if it has already been built.

And I have another that I plan to port which is thrice the size—but getting toward a minute would be hard to stomach for trivial changes.

If I insert a simple TypeScript error in one of the files:

  • @alexlur/rollup-plugin-typescript: it produces the errors to stderr after about 0.8 seconds:

    /mnt/c/fastmail/overture/source/Overture/core/Core.js(171,16): error TS8010: 'types' can only be used in a .ts file.
    🚨   There were TypeScript errors transpiling
    source/Overture/core/Core.js
    
  • rollup-plugin-typescript2: it produces much the same output (though slightly differently formatted—notably lacking the error codes) to stderr after about 3.4 seconds:

    🚨   rpt2: /mnt/c/fastmail/overture/source/Overture/core/Core.js (171,16): 'types' can only be used in a .ts file.
    source/Overture/core/Core.js
    

At this stage I can’t see any reason why I should use this plugin rather than @alexlur’s. Performance is a major feature.

Could not generate sourcemap files -- set `sourcemap: true` in Rollup config

What happens and why it is wrong

Could not generate sourcemap files

Versions

  • typescript: 2.7.2
  • rollup: 0.54.1
  • rollup-plugin-typescript2: 0.10.0

rollup.config.js

import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import commonjs from 'rollup-plugin-commonjs';

const config = {
  input: './src/index.ts',
  output: {
    file: './lib/index.js',
    format: 'es',
  },
  plugins: [
    // rollup-plugin-node-resolve
    resolve(),
    // rollup-plugin-typescript2
    typescript({
      tsconfigDefaults: {
        sourceMap: true,
      },
    }),
    // rollup-plugin-commonjs
    commonjs(),
  ],
  external: Object.keys(require('./package.json').dependencies),
};

export default config;

tsconfig.json

{
  "include": [
    "src",
  ],
  "exclude": [
    "node_modules"
  ],
  "compilerOptions": {
    "target": "es5", 
    "module": "es2015",
    "lib": ["es2015", "es2015.core", "dom"], 
    "jsx": "react", 
    "declaration": true,   
    "sourceMap": true,
    "removeComments": true, 
    "strict": true,
    "strictPropertyInitialization": false,
    "allowSyntheticDefaultImports": true
  }
}

How to handle rootDirs outside a project root?

I have a Lerna project with this structure:

<root>
│   package.json
│   tsconfig.json
│
├───packages
│   ├───foo
│   │   │   package.json
│   │   │   rollup.config.js
│   │   │   tsconfig.json
│   │   │
│   │   └───src
│   │           foo.ts
│   │           index.ts
│   │
│
└───shared
    └───utils
        │   index.ts
        │   style-cache.ts
        │
        └───decorator
                decorators.ts

I'm using TypeScript's rootDirs option to include the shared/utils folder in my foo build: https://www.typescriptlang.org/docs/handbook/module-resolution.html#virtual-directories-with-rootdirs

This works fine when compiling with tsc, but it's failing on the Rollup build with errors like:

[!] Error: Unexpected token
..\..\shared\utils\decorator\decorators.ts (2:26)
1: import { styleCacheSingleton } from '../style-cache';
2: const makeDecorator = (key: string) => {
                             ^

After debugging it appears the reason this is happening is that the file in shared/utils are being excluded from TypeScript processing.

This is the result of the createFilter function, which by default does a path.resolve() wherever the Rollup command is being invoked: https://github.com/rollup/rollup-pluginutils/blob/master/src/createFilter.js#L6

So! I'm looking for feedback on how you think I should resolve this. I can work around it by manually adding the out-of-directory folder to an include list:

  plugins: [
    ts({
      include: ['**/*.ts', '../../shared/**/*.ts']
    })
  ]

But, it feels to me like this should be handled automatically by this plugin if it finds a rootDirs folder in tsconfig. What do you think? Is it worth putting a PR together? Or is there a better way for me to handle this?

tsconfig `include` not overridden

#It's either a bug or maybe a wanted functionality. Here are my tsconfig file and plugin options which work well:
tsconfig.dist.esm.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "dist/esm"
  },
  "include": ["src/**/*.ts"]
}

rollup.config.js:

typescript({
  tsconfig: 'tsconfig.dist.esm.json',
  useTsconfigDeclarationDir: true
})

I wanted to rid of tsconfig.dist.esm.json and thus modified rollup.config.js file:

typescript({
  tsconfig: 'tsconfig.dist.esm.json',
  tsconfigOverride: {
    compilerOptions: {
      declaration: true,
      declarationDir: 'dist/esm'
    },
    include: ['src/**/*.ts']
  },
  useTsconfigDeclarationDir: true
})

But it does not work. The plugin does not pay attention to txconfigOverride.compilerOptions.declarationDir option. Would be nice if it could.

Doesn’t resolve module with `moduleResolution: "classic"`

Hi, with a file containing

import C from './components/C'

i get:

🚨   rpt2: /home/phil/Dev/Web/flying-sheep.github.com/src/index.tsx (4,15):
Cannot find module './components/C'.

even though it’s there:

$ tree src
src
├── components
│   └── C
│       ├── index.tsx
│       ├── style.css
│       └── style.css.d.ts
└── index.tsx

if i change it to this:

import C from './components/C/index'

i get:

🚨   Could not resolve './components/C/index' from
/home/phil/Dev/Web/flying-sheep.github.com/src/index.tsx

my tsconfig.json has:

"include": [
	"src/**/*"
]

and my rollup.config.js:

plugins: [
	nodeResolve(),
	commonjs(),
	typescript({
		verbosity: 3,
		clean: true,
		check: true,
	}),
]

Helpers missing from output file for a TS script (instead of module)

I get a Uncaught ReferenceError: __awaiter is not defined when compiling a file with async. I'm using the latest TypeScript (2.6.2), rollup (0.53.0) and plugin (0.9.0).

main.ts

async function main() {
}
main();

rollup.config.js

import typescript from 'rollup-plugin-typescript2';

export default {
  output: {
    format: 'iife'
  },
  plugins: [
    typescript()
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "lib": [
      "es2015"
    ]
  }
}

main.js:

(function () {
'use strict';

function main() {
    return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            return [2 /*return*/];
        });
    });
}
main();

}());

`.rpt2_cache` should be in `/tmp`

Instead of having .rpt2_cache directory created inside the "working/current" directory, it should be in /tmp so that users don't have to .gitignore it.

TS Fatal error out-of-memory -- don't `include` `node_modules`

Hi,

I'm trying to use rollup Javascript API in our internal build tool and sometimes it happens to me that typescript fail on same low level Fatal error like on the picture below

image

I don't know why, because it happens irregularly, once after 3. rebuild, next time after 15. rebuild.

My rollup config is really simple and looks like this

import rollup from "rollup";
import typescript from "rollup-plugin-typescript2";
	cache = {};

rollup.rollup({
	entry: "login/src/index.ts",
	plugins: [
		typescript({
			include: module + "login/src/**/*.ts",
			cacheRoot: tempDir + "/.rts2_cache"
		})
	],
	cache: cache[module] || false
}).then(function (bundle) {
	cache[module] = bundle;

	return bundle.write({
		format: "iife",
		moduleName: "app.login",
		dest: "login/dist/login.bundle.js"
	});
});

I tried Typescript version 2.1.6 and 2.2.2, both behave same. Don't you have any hint what could I try to avoid it, or at least handle it?

watch mode error for non-TS files (Handlebars, Vue)

I import Handlebars template files which should be ignored by the diagnostics.

Error: Could not find file: '/Users/mohamed/project/src/Views/Shared/spaces.hbs'.
    at getValidSourceFile (/Users/mohamed/project/node_modules/typescript/lib/typescript.js:91281:23)
    at Object.getSyntacticDiagnostics (/Users/mohamed/project/node_modules/typescript/lib/typescript.js:91504:52)
    at /Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:629:74
    at /Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:325:80
    at arrayEach (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:9359:14)
    at TsCache.walkTree (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:325:9)
    at Object.ongenerate (/Users/mohamed/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:628:17)
    at bundle.plugins.forEach.plugin (/Users/mohamed/project/node_modules/rollup/dist/rollup.js:10507:16)
    at Array.forEach (<anonymous>)

`importHelpers: true` option doesn't import `tslib` and is still inlining helpers -- need to configure Rollup `external`s

What happens and why it is wrong

I tried to compile a simple class with an async method:

class TestClass {
	static async fetchJson(url) {
		const response = await fetch(url);
		const data = await response.json();

		return { ...data }
	}
}
export { TestClass };

and I expect "importHelpers": true, to be respected and tslib to be added to the output. Instead I can see in the output that __assign, __awaiter and __generator are present.

Running npx tsc src/index.ts --importHelpers --lib 'dom,ES2015' --target 'es5' --moduleResolution 'node' --declaration --noEmitHelpers directly does work and generates var tslib_1 = require("tslib");.

Versions

  • typescript:
$ npm ls typescript
[email protected] /Users/damienseguin/Projects/#test/test-class
└── [email protected]
  • rollup:
$ npm ls rollup
[email protected] /Users/damienseguin/Projects/#test/test-class
└── [email protected]
  • rollup-plugin-typescript2:
$ npm ls rollup-plugin-typescript2
[email protected] /Users/damienseguin/Projects/#test/test-class
└── [email protected]

rollup.config.js

import resolve from "rollup-plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";

export default {
  input: "src/index.ts",
  plugins: [
    resolve(),
    typescript({
      typescript: require("typescript"),
      clean: true,
      verbosity: 3
    }),
  ],
  output: [
    {
      format: "umd",
      file: "lib/test-class.js",
      name: "TestClass"
    },
    {
      format: "es",
      file: "lib/test-class.module.js"
    }
  ]
};

tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "importHelpers": true,
    "moduleResolution": "node",
    "target": "es5",
    "lib": ["dom", "es2015"]
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

package.json

{
  "name": "test-class",
  "main": "lib/test-class.js",
  "jsnext:main": "lib/test-class.module.js",
  "module": "lib/test-class.module.js",
  "types": "lib/index.d.ts",
  "scripts": {
    "dev": "rollup -c -w -m inline",
    "clean": "rm -rf lib",
    "build": "rollup -c"
  },
  "devDependencies": {
    "rollup": "^0.56.3",
    "rollup-plugin-node-resolve": "^3.0.3",
    "rollup-plugin-typescript2": "^0.11.1",
    "rollup-watch": "^4.3.1",
    "tslint": "^5.9.1",
    "typescript": "^2.7.2"
  },
  "dependencies": {
    "tslib": "^1.9.0"
  }
}

plugin output with verbosity 3

Output
src/index.ts → lib/test-class.js, lib/test-class.module.js...
rpt2: typescript version: 2.7.2
rpt2: rollup-plugin-typescript2 version: 0.11.1
rpt2: plugin options:
{
    "typescript": "version 2.7.2",
    "clean": true,
    "verbosity": 3,
    "check": true,
    "cacheRoot": "/Users/damienseguin/Projects/#test/test-class/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "tsconfigDefaults": {}
}
rpt2: rollup config:
{
    "input": "src/index.ts",
    "plugins": [
        {
            "name": "node-resolve"
        },
        {
            "name": "rpt2"
        }
    ],
    "entry": "src/index.ts",
    "external": [
        "",
        ""
    ]
}
rpt2: built-in options overrides: {
    "module": 5,
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "outDir": "/Users/damienseguin/Projects/#test/test-class",
    "moduleResolution": 2,
    "declarationDir": "/Users/damienseguin/Projects/#test/test-class"
}
rpt2: parsed tsconfig: {
    "options": {
        "declaration": true,
        "importHelpers": true,
        "moduleResolution": 2,
        "target": 1,
        "lib": [
            "lib.dom.d.ts",
            "lib.es2015.d.ts"
        ],
        "module": 5,
        "noEmitHelpers": false,
        "noResolve": false,
        "noEmit": false,
        "outDir": "/Users/damienseguin/Projects/#test/test-class",
        "declarationDir": "/Users/damienseguin/Projects/#test/test-class",
        "configFilePath": "/Users/damienseguin/Projects/#test/test-class/tsconfig.json"
    },
    "fileNames": [
        "/Users/damienseguin/Projects/#test/test-class/src/index.ts",
        "/Users/damienseguin/Projects/#test/test-class/src/types.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "declaration": true,
            "importHelpers": true,
            "moduleResolution": "node",
            "target": "es5",
            "lib": [
                "dom",
                "es2015"
            ]
        },
        "include": [
            "src/**/*"
        ],
        "exclude": [
            "node_modules",
            "**/*.spec.ts"
        ]
    },
    "errors": [],
    "wildcardDirectories": {
        "/users/damienseguin/projects/#test/test-class/src": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "src/**/*"
        ],
        "excludeSpecs": [
            "node_modules",
            "**/*.spec.ts"
        ],
        "validatedIncludeSpecs": [
            "src/**/*"
        ],
        "validatedExcludeSpecs": [
            "node_modules",
            "**/*.spec.ts"
        ],
        "wildcardDirectories": {
            "/users/damienseguin/projects/#test/test-class/src": 1
        }
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: Ambient types:
rpt2: cleaning cache: /Users/damienseguin/Projects/#test/test-class/.rpt2_cache/7247f35da223bc044adbbddbc34442c3554b0160
rpt2: transpiling '/Users/damienseguin/Projects/#test/test-class/src/index.ts'
rpt2:     cache: '/Users/damienseguin/Projects/#test/test-class/.rpt2_cache/7247f35da223bc044adbbddbc34442c3554b0160/code/cache/efbe672c2695ac546f259f206ba52ed5aca5d46b'
rpt2:     cache miss
rpt2:     cache: '/Users/damienseguin/Projects/#test/test-class/.rpt2_cache/7247f35da223bc044adbbddbc34442c3554b0160/syntacticDiagnostics/cache/efbe672c2695ac546f259f206ba52ed5aca5d46b'
rpt2:     cache miss
rpt2:     cache: '/Users/damienseguin/Projects/#test/test-class/.rpt2_cache/7247f35da223bc044adbbddbc34442c3554b0160/semanticDiagnostics/cache/efbe672c2695ac546f259f206ba52ed5aca5d46b'
rpt2:     cache miss
rpt2: generated declarations for '/Users/damienseguin/Projects/#test/test-class/src/index.ts'
rpt2: generating target 1
rpt2: rolling caches
rpt2: generating missed declarations for '/Users/damienseguin/Projects/#test/test-class/src/types.ts'
rpt2: writing declarations for '/Users/damienseguin/Projects/#test/test-class/src/index.ts' to '/Users/damienseguin/Projects/#test/test-class/lib/index.d.ts'
rpt2: writing declarations for '/Users/damienseguin/Projects/#test/test-class/src/types.ts' to '/Users/damienseguin/Projects/#test/test-class/lib/types.d.ts'
rpt2: generating target 2
rpt2: rolling caches
rpt2: writing declarations for '/Users/damienseguin/Projects/#test/test-class/src/index.ts' to '/Users/damienseguin/Projects/#test/test-class/lib/index.d.ts'
rpt2: writing declarations for '/Users/damienseguin/Projects/#test/test-class/src/types.ts' to '/Users/damienseguin/Projects/#test/test-class/lib/types.d.ts'
created lib/test-class.js, lib/test-class.module.js in 629ms

`TS2354` error: `module 'tslib' cannot be found` -- use `moduleResolution: "node"`

tsconfig.json

{
  "compilerOptions": {
      "outDir": "dist",
      "module": "es2015",
      "target": "es2015"
  },
  "include": [
      "src"
  ]
}

src/test.ts

export default async function hello() {
  console.log('Hello world')
}

run rollup -c Error:

Error: rpt2: rollup-example/src/test.ts (3,23): semantic error TS2354 This syntax requires an imported helper but module 'tslib' cannot be found.

but change to rollup-plugin-typescript, run successful.

`Unexpected token error` (`ɵ`) with Rollup but not webpack

Problem

I'm working on angular(4+) aot compile things, and I can get a output with webpack. In order to get a better performance and smaller bundle size, I try rollup these days, but got a puzzling error.

{ Error: Unexpected token
    at error (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:177:12)
    at Module.error$1 [as error] (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:8434:2)
    at tryParse (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:8133:10)
    at new Module (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:8169:14)
    at /Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:10010:17
  code: 'PARSE_ERROR',
  pos: 4126,
  loc:
   { file: '/Users/xiatianhan/Coding/Tech/newBuild/captial/.tmp/aot/.tmp/src/app/app/app-ng2.module.ngfactory.ts',
     line: 63,
     column: 57 },
  frame: '61: import * as import52 from \'@angular/animations/browser\';\n62: import * as import53 from \'ionic-angular/components/app/app-root\';\n63: class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {\n                                  ^\n64:   _CommonModule_0:import2.CommonModule;\n65:   _ɵba_1:import3.ɵba;' }

It's should be a legal grammar, and the verison(2.1.6 or 2.4.2) and tsconfig of typescript I used to compile with webpack and rollup is the same.

Rollup Config

rollup.rollup({
    entry: '.tmp/aot/.tmp/src/app/app/app-ng2.module.ngfactory.ts',
    sourceMap: false,
    format: 'iife',
    onwarn: function (warning) {
        if (warning.code === 'THIS_IS_UNDEFINED') {
            return;
        }
        console.warn(warning.message);
    },
    external: [
        '@jdb/ng2-lib'
    ],
    paths: {
        '@jdb/ng2-lib': 'ng2lib'
    },
    globals: {
        '@jdb/ng2-lib': 'ng2lib'
    },
    plugins: [
        angular({
            exclude: ['node_modules/ionic-angular/**/*'],
            preprocessors: {
                template: template => minify(template, htmlminOpts),
                style: scss => {
                    let css = sass.renderSync({
                        data: scss
                    }).css;
                    css = postcss([autoprefixer({browsers: [
                        "iOS 7",
                        "iOS 8",
                        "Android 4"
                    ]})]).process(css).css;
                    return cssmin.minify(css).styles;
                },
            }
        }),
        nodeResolve({
            jsnext: true,
            module: true
        }),
        typescript({
            tsconfig: "tsconfig.build.json",
            verbosity: 3,
            clean: true,
            check: false,
            abortOnError: false
        }),
        commonjs({
            include: [
                'node_modules/rxjs/**',
                'node_modules/query-string/**',
                'node_modules/strict-uri-encode/index.js'
            ]
        })
        // uglify()
    ]
})

Log

The whole log

start rollup
Typescript version: 2.4.2
rpt2: Typescript version: 2.4.2
rpt2: Options: {
    "tsconfig": "tsconfig.build.json",
    "verbosity": 3,
    "clean": true,
    "check": false,
    "abortOnError": false,
    "cacheRoot": "/Users/xiatianhan/Coding/Tech/newBuild/captial/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "rollupCommonJSResolveHack": false
}
{ config:
   { compilerOptions:
      { target: 'es5',
        module: 'es2015',
        moduleResolution: 'node',
        sourceMap: true,
        emitDecoratorMetadata: true,
        experimentalDecorators: true,
        lib: [Object],
        noImplicitAny: false,
        suppressImplicitAnyIndexErrors: true,
        outDir: '.tmp/out',
        allowJs: true,
        rootDir: '.',
        baseUrl: '.',
        paths: [Object] },
     include: [ '.tmp/**/*' ],
     exclude:
      [ '.tmp/common_modules/**/*',
        'node_modules',
        './src/main.aot.ts',
        'dist',
        'temp/**/*',
        '**/*.spec.ts',
        '.tmp/main-aot.ts' ],
     compileOnSave: false,
     angularCompilerOptions: { genDir: './.tmp/aot', skipMetadataEmit: true } } }
rpt2: rollupConfig: {
    "entry": ".tmp/aot/.tmp/src/app/app/app-ng2.module.ngfactory.ts",
    "sourceMap": false,
    "format": "iife",
    "external": [
        "@jdb/ng2-lib"
    ],
    "paths": {
        "@jdb/ng2-lib": "ng2lib"
    },
    "globals": {
        "@jdb/ng2-lib": "ng2lib"
    },
    "plugins": [
        {
            "name": "angular"
        },
        {
            "name": "node-resolve"
        },
        {},
        {
            "name": "commonjs"
        }
    ]
}
rpt2: Ambient types:
rpt2:     /Users/xiatianhan/Coding/Tech/newBuild/captial/.tmp/src/app/global.d.ts
rpt2:     /Users/xiatianhan/Coding/Tech/newBuild/captial/.tmp/src/app/typings.d.ts
rpt2:     /Users/xiatianhan/Coding/Tech/newBuild/captial/.tmp/src/tradeCaptial/global.d.ts
rpt2:     /Users/xiatianhan/Coding/Tech/newBuild/captial/node_modules/@types/angular/index.d.ts
rpt2:     /Users/xiatianhan/Coding/Tech/newBuild/captial/node_modules/@types/jquery/index.d.ts
rpt2:     /Users/xiatianhan/Coding/Tech/newBuild/captial/node_modules/@types/node/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: cleaning cache: /Users/xiatianhan/Coding/Tech/newBuild/captial/.rpt2_cache/dfae67991e14befd28a9f94f64044ea70e5c3030
{ Error: Unexpected token
    at error (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:177:12)
    at Module.error$1 [as error] (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:8434:2)
    at tryParse (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:8133:10)
    at new Module (/Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:8169:14)
    at /Users/xiatianhan/Coding/Tech/newBuild/@jdb/ngu/node_modules/rollup/dist/rollup.js:10010:17
  code: 'PARSE_ERROR',
  pos: 4126,
  loc:
   { file: '/Users/xiatianhan/Coding/Tech/newBuild/captial/.tmp/aot/.tmp/src/app/app/app-ng2.module.ngfactory.ts',
     line: 63,
     column: 57 },
  frame: '61: import * as import52 from \'@angular/animations/browser\';\n62: import * as import53 from \'ionic-angular/components/app/app-root\';\n63: class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {\n                                  ^\n64:   _CommonModule_0:import2.CommonModule;\n65:   _ɵba_1:import3.ɵba;' }

Error when using dynamic import -- support `esnext`

What happens and why it is wrong

When using dynamic imports the following error is thrown:

[!] (rpt2 plugin) Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
a.ts
Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
    at error (/home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:170:15)
    at /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:17346:17
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

This is caused by this module forcefully setting the module compiler option to es2015.

Environment

a.ts

import('./b').then(({ message }) => console.log(message));

b.ts

export const message = 'it works!';

Versions

  • typescript: 2.6.2
  • rollup: 0.53.4
  • rollup-plugin-typescript2: 0.9.0

rollup.config.js

"use strict";

import typescript from "rollup-plugin-typescript2";

export default {
  input: "./a.ts",
  output: {
    format: "cjs",
  },

  plugins: [
    typescript({
      tsconfig: './tsconfig.json',
      verbosity: 3,
    })
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2015"
  }
}

plugin output with verbosity 3

rpt2: typescript version: 2.8.0-dev.20180131
rpt2: rollup-plugin-typescript2 version: 0.9.0
rpt2: plugin options:
{
    "tsconfig": "./tsconfig.json",
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "typescript": "version 2.8.0-dev.20180131",
    "tsconfigOverride": {}
}
rpt2: rollup config:
{
    "input": "./a.ts",
    "plugins": [
        {
            "name": "rpt2"
        }
    ],
    "entry": "./a.ts",
    "external": [
        "",
        ""
    ]
}
rpt2: built-in options overrides: {
    "module": 5,
    "noEmitHelpers": true,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "outDir": "/home/leo/development/other/rollup-plugin-typescript2-debug",
    "moduleResolution": 2
}
rpt2: parsed tsconfig: {
    "options": {
        "module": 5,
        "target": 2,
        "outDir": "/home/leo/development/other/rollup-plugin-typescript2-debug",
        "baseUrl": "/home/leo/development/other/rollup-plugin-typescript2-debug/src/",
        "sourceMap": true,
        "strict": true,
        "experimentalDecorators": true,
        "noImplicitReturns": true,
        "allowSyntheticDefaultImports": true,
        "allowUnreachableCode": false,
        "noEmitHelpers": true,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "moduleResolution": 2,
        "configFilePath": "/home/leo/development/other/rollup-plugin-typescript2-debug/./tsconfig.json"
    },
    "fileNames": [
        "/home/leo/development/other/rollup-plugin-typescript2-debug/a.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/b.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/a.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/main.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/types.d.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/utils/ErrorMapper.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "module": "commonjs",
            "target": "es2015",
            "outDir": "dist",
            "baseUrl": "src/",
            "sourceMap": true,
            "strict": true,
            "experimentalDecorators": true,
            "noImplicitReturns": true,
            "allowSyntheticDefaultImports": true,
            "allowUnreachableCode": false
        },
        "exclude": [
            "node_modules"
        ]
    },
    "errors": [],
    "wildcardDirectories": {
        "/home/leo/development/other/rollup-plugin-typescript2-debug": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "**/*"
        ],
        "excludeSpecs": [
            "node_modules"
        ],
        "validatedIncludeSpecs": [
            "**/*"
        ],
        "validatedExcludeSpecs": [
            "node_modules"
        ],
        "wildcardDirectories": {
            "/home/leo/development/other/rollup-plugin-typescript2-debug": 1
        }
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: Ambient types:
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/src/types.d.ts
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/@types/lodash/index.d.ts
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/@types/node/index.d.ts
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/@types/screeps/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling '/home/leo/development/other/rollup-plugin-typescript2-debug/a.ts'
rpt2:     cache: '/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache/cd81cf42f3dcf638d9c3e61868cbf69ad7637cd0/code/cache/f11ac0bffbde51209d9a516866cafbe3aca2435c'
rpt2:     cache miss
rpt2:     cache: '/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache/cd81cf42f3dcf638d9c3e61868cbf69ad7637cd0/syntacticDiagnostics/cache/f11ac0bffbde51209d9a516866cafbe3aca2435c'
rpt2:     cache miss
rpt2:     cache: '/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache/cd81cf42f3dcf638d9c3e61868cbf69ad7637cd0/semanticDiagnostics/cache/f11ac0bffbde51209d9a516866cafbe3aca2435c'
rpt2:     cache miss
[!] (rpt2 plugin) Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
a.ts
Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
    at error (/home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:170:15)
    at /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:17346:17
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

Can't use this plugin with rollup watch

When using rollup in watch mode (rollup --watch) this plugin will allow the first build but no following one. Each time I change a file it tells me:

bundling...
� ENOENT: no such file or directory, open '.../.cache/rollup-plugin-typescript2/38c1142761dfd23593156a9ffdbc77dede334f14/code/cache_/ff351ee7256cf7
98f62b4f46f09ac4534010406c'
src/gl/gl.tsx

The file does not exist, but I guess it's the hash of the new file. In this scenario, I changed some code in src/gl/gl.tsx, which lead to the rebuild.

Stopping rollup --watch and rerunning it generates a valid bundle, but every following build afterwards are breaking as well.

I'm using rollup 0.41.5, rollup-plugin-typescript2 0.3.0 and node 6.9.1

Trouble using `require` with `rollup-plugin-commonjs` -- use TS `import` syntax instead

config

// rollup.config.js
import typescript from 'rollup-plugin-typescript2';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve'

export default {
  input: 'src/index.ts',
  output: {
    format: 'es',
    file: 'dist/index.js'
  },

  plugins: [
    typescript(),
    nodeResolve(),
    commonjs()
  ]
}

input

// index.ts
var f = require('untypedModule')
f()

output

// dist/index.js
var f = require('untypedModule')
f()

when typescript() removed from plugins array

// dist/index.js
function f() {...}
f()

As you can see 'typescript-plugin' somehow prevents 'commonJs' and 'nodeResolve' to produce proper output

If I remove 'typescript-plugin' from chain, the output is correct

Please help.

Error: `Unexpected token` in `.jsx` file -- can't repro

What happens and why it is wrong

When run rollup -c. It will cause Error: Unexpected token

ReactDOM.render(
     <App></App>,
      ^
   document.getElementById("app")
)

Environment

Versions

  • typescript: 2.6.2
  • rollup: 0.55.0
  • rollup-plugin-typescript2: 0.10.0

rollup.config.js

import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import filesize from 'rollup-plugin-filesize';
import progress from 'rollup-plugin-progress';
import postcss from 'rollup-plugin-postcss';
import alias from 'rollup-plugin-alias';
import css from 'rollup-plugin-css-only';
import typescript from 'rollup-plugin-typescript2';
import path from 'path';


const config = {
    input: './src/index.jsx',
    output: {
        file: './lib/bundle.js',
        format: 'es',
        name: 'app',
        banner: '/* This is banner */',
        footer: '/* This is footer */',
    },
    plugins: [
        css({
            output: './lib/bundle.css'
        }),
        resolve({
            extensions: ['.js', '.jsx', '.ts', '.tsx']
        }),
        typescript(),
        commonjs(),
        alias({
            spark: path.resolve(__dirname, '../../bytedance/spark/lib/index')
        }),
        json(),
        filesize(),
        progress(),
    ],

    external: [
        'react',
        'react-dom',
    ]
}

export default config;

tsconfig.json

{
  "include": [
    "**/*.js",
    "**/*.jsx"
  ],
  "exclude": [
    "test",
    "node_modules",
    "*.config.js"
  ],
  "compilerOptions": {
    "target": "es2015", 
    "module": "es2015",
    "allowJs": true,       
    "checkJs": true,                
    "jsx": "react",  

    "strict": true,  

    "moduleResolution": "node",   
    "allowSyntheticDefaultImports": true, 
  }
}

package.json

{
  "name": "tree-shaking-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server",
    "build": "rollup -c"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/react": "^16.0.34",
    "@types/react-dom": "^16.0.3",
    "antd": "^3.1.4",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-external-helpers": "^6.22.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-es2015-loose-rollup": "^7.0.0",
    "babel-preset-es2015-rollup": "^3.0.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "babelrc-rollup": "^3.0.0",
    "clean-webpack-plugin": "^0.1.17",
    "css-loader": "^0.28.8",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^1.1.6",
    "html-loader": "^0.5.4",
    "html-webpack-plugin": "^2.30.1",
    "lodash": "^4.17.4",
    "react-hot-loader": "^4.0.0-beta.14",
    "rollup": "^0.55.0",
    "rollup-plugin-alias": "^1.4.0",
    "rollup-plugin-babel": "^3.0.3",
    "rollup-plugin-css-only": "^0.4.0",
    "rollup-plugin-filesize": "^1.5.0",
    "rollup-plugin-json": "^2.3.0",
    "rollup-plugin-node-resolve": "^3.0.2",
    "rollup-plugin-postcss": "^1.2.5",
    "rollup-plugin-progress": "^0.4.0",
    "rollup-plugin-typescript": "^0.8.1",
    "rollup-plugin-typescript2": "^0.10.0",
    "style-loader": "^0.19.1",
    "uglifyjs-webpack-plugin": "^1.1.6",
    "webpack": "^3.10.0"
  },
  "dependencies": {
    "react": "^16.2.0",
    "react-addons-css-transition-group": "^15.6.2",
    "react-dom": "^16.2.0",
    "react-transition-group": "^2.2.1",
    "rollup-plugin-commonjs": "^8.2.6",
    "the-answer": "^1.0.0",
    "typescript": "^2.6.2"
  }
}

`allowJs` and `outDir` `compilerOptions` -- need to set plugin `include`

I am using tsc to transpile ES6 javascript to ES5, by using

compilerOptions: {
        "allowJs": true,
        "outDir": "./build",
      // ...
},

In my rollup.config.js, I have input: 'build/index.js',
My build script is then tsc && rollup -c. This seems to work fine.

I would like to be able to use rollup-plugin-typescript2, rather than calling tsc on the command line, but rollup-plugin-typescript2 seems to disallow the outDir option. The docs say this option is forced. "outDir: process.cwd()". Would it be possible to support this workflow with rollup-plugin-typescript2?

watcher crashes periodically, saying heap out of memory

often the crash is silent so the electron app continues to run

<--- Last few GCs --->

[84784:0x104001600]  1682282 ms: Mark-sweep 1415.5 (1500.8) -> 1415.5 (1500.8) MB, 1185.2 / 0.0 ms  allocation failure scavenge might not succeed
[84784:0x104001600]  1683465 ms: Mark-sweep 1415.5 (1500.8) -> 1415.5 (1482.8) MB, 1182.3 / 0.0 ms  last resort 
[84784:0x104001600]  1684750 ms: Mark-sweep 1415.5 (1482.8) -> 1415.5 (1482.8) MB, 1284.1 / 0.0 ms  last resort 


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0xd6dfe69cef1 <JSObject>
    0: builtin exit frame: stringify(this=0xd6dfe6ae341 <JSON map = 0x22aa59c0ec79>,4,0xd6dfe682241 <undefined>,0x3ffd8d3e3d91 <Object map = 0x3702d544bbb1>)

    1: options [/Users/michaelmclaughlin/Sites/specless/cloud-compiler/sync/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:~19778] [pc=0x3b4849232fb2](this=0x3ffd8d3e0da1 <Object map = 0x3702d544b1b9>,config=0x...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 6: v8::internal::IncrementalStringBuilder::Extend() [/usr/local/bin/node]
 7: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
 8: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
 9: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
10: v8::internal::JsonStringifier::SerializeArrayLikeSlow(v8::internal::Handle<v8::internal::JSReceiver>, unsigned int, unsigned int) [/usr/local/bin/node]
11: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
12: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
13: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
14: v8::internal::JsonStringifier::SerializeArrayLikeSlow(v8::internal::Handle<v8::internal::JSReceiver>, unsigned int, unsigned int) [/usr/local/bin/node]
15: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
16: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
17: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
18: v8::internal::JsonStringifier::Stringify(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
19: v8::internal::Builtin_Impl_JsonStringify(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
20: 0x3b48489bc8dd```

Error: `Cannot read property 'length' of undefined` with `tsx` file and `jsx: "preserve"` setting

When processing a tsx source file I get an error, however if I manually compile with tsc I don't get an error.

Environment:

Windows: 10
NodeJS: 7.10
NPM: 5.0.4

Project structure

./
  tsconfig.json
  package.json
  rollup.config.js
  src/
    main.ts
    jsx-utils.ts
    components/
      topbar.tsx

Here's a gist with the relevant files in the above structure.

Error:

$ npm run build

> [email protected] build C:\repos\testtsx
> rollup -c

🚨   Cannot read property 'length' of undefined
src\components\topbar.tsx

I was using the older typescript plugin, rollup-plugin-typescript and just require'd in my local typescript, and that worked, but found that this existed so I gave it a whirl.

Let me know if I have something setup wrong! <3<3 Thanks for reading.

`rpt2: options error TS2688 Cannot find type definition file` with TS 2.4

Hi,

Moving on typescript 2.4.1 breaks transpilation.

Verbosity 3 trace (I replaced cwd)

rpt2: Typescript version: 2.4.1
rpt2: Options: {
    "clean": true,
    "verbosity": 3,
    "abortOnError": false,
    "check": true,
    "cacheRoot": "{cwd}/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "rollupCommonJSResolveHack": false,
    "tsconfig": "tsconfig.json" // file is present
}
rpt2: options error TS2688 Cannot find type definition file for 'mocha'.
rpt2: options error TS2688 Cannot find type definition file for 'node'.
rpt2: rollupConfig: {
    "entry": "./index.ts",
    "dest": "umd/index.js",
    "format": "umd",
    "moduleName": "Santech.Core",
    "plugins": [
        {}
    ],
    "external": [
        ""
    ]
}
rpt2: Ambient types:
rpt2:     {cwd}/node_modules/@types/mocha/index.d.ts // file is present
rpt2:     {cwd}/node_modules/@types/node/index.d.ts // file is present
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: cleaning cache: {cwd}/.rpt2_cache/214064424104a2d72baf4ffd272fdce93c6b7a9b
rpt2: transpiling '{cwd}/index.ts'
rpt2:     cache: '{cwd}/.rpt2_cache/214064424104a2d72baf4ffd272fdce93c6b7a9b/code/cache/6910cdcfa786703b677dcee336da7d03c4bfbfe3'
rpt2:     cache miss
rpt2:     cache: '{cwd}/.rpt2_cache/214064424104a2d72baf4ffd272fdce93c6b7a9b/syntacticDiagnostics/cache/6910cdcfa786703b677dcee336da7d03c4bfbfe3'
rpt2:     cache miss
rpt2:     cache: '{cwd}/.rpt2_cache/214064424104a2d72baf4ffd272fdce93c6b7a9b/semanticDiagnostics/cache/6910cdcfa786703b677dcee336da7d03c4bfbfe3'
rpt2:     cache miss
⚠️   rpt2: {cwd}/index.ts (1,15): semantic error TS2307 Cannot find module './lib/http'.
index.ts

⚠️   rpt2: {cwd}/index.ts (2,15): semantic error TS2307 Cannot find module './lib/jwt'.
index.ts

⚠️   rpt2: {cwd}/index.ts (3,15): semantic error TS2307 Cannot find module './lib/storage'.
index.ts

rpt2: dependency '{cwd}/lib/http.ts'
rpt2:     imported by '{cwd}/index.ts'
rpt2: resolving './lib/http'
rpt2:     to '{cwd}/lib/http.ts'
rpt2: transpiling '{cwd}/lib/http.ts'
rpt2:     cache: '{cwd}/.rpt2_cache/214064424104a2d72baf4ffd272fdce93c6b7a9b/code/cache/ef9ea006b79a2162a89f467df12986dbc8ebff68'
rpt2:     cache miss
🚨   Could not find file: '{cwd}/lib/http.ts'.
lib\http.ts

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "declaration": true,
    "sourceMap": true,
    "outDir": "dist",
    "typeRoots": [
      "./node_modules/@types"
    ],
    "types": [
      "mocha",
      "node"
    ],
    "lib": [
      "dom",
      "es6",
      "es2016.array.include"
    ]
  },
  "files": [
    "./index.ts"
  ],
  "exclude": [
    "coverage",
    "dist",
    "docs",
    "node_modules"
  ]
}

Moving back on typescript 2.3.4 solves the problem.

Thanks anyway for the great job

Plugin should ignore corrupted cache

Sometimes cache gets corrupted, and plugin throws JSON exception (when build interrupted in wrong place).

[10:30:58] Error: ./.cache/0e05bd66949fbb4a048b752195b45acaa4973026/code/cache/1ebf05433ba5ed0b148851cac444c0fb84ba87c1: Unexpected end of JSON input
    at error (D:\source\scr\screeps-ts\node_modules\rollup\dist\rollup.js:170:12)
    at D:\source\scr\screeps-ts\node_modules\rollup\dist\rollup.js:8926:6
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)

Should catch and fallback instead. Alternatively, use transactions.

Workaround -- cleaning cache and rebuilding.

Ability to specify default tsconfig options

Hello,

I am trying to make microbundle switch to using this plugin for typescript compilation (see developit/microbundle#71).

As part of that change (and to keep with the #0CJS approach of microbundle) we'd like to generate declaration by default when the user does not provide a tsconfig.json. However if the user explicitly does not want declaration files to be generated, we should respect that.

Currently there is only a way to override tsconfig options with tsconfigOverride. Would you be open to adding a tsconfigDefaults option that would be overridden by explicit tsconfig.json values ?

`noEmitOnError: false` seems to be ignored -- use plugin option `abortOnError`

What happens and why it is wrong

Semantic errors result in no emit. Adding noEmitOnError: false doesn't help.

Error:

[!] (rpt2 plugin) Error: /Users/.....ts(1286,2): semantic error TS2300 Duplicate identifier 'on'.

Versions

  • typescript: 2.7.2
  • rollup: 0.51.8
  • rollup-plugin-typescript2: 0.11.1

rollup.config.js

config.plugins[0] = typescript({
  target: 'es6',
  isolatedModules: true,
  module: 'es6',
  typescript: tsc,
  noEmitOnError: false
})

tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "declaration": true,
        "removeComments": false,
        "lib": ["es2017", "dom"],
        "sourceMap": true,
        "strict": true,
        "suppressImplicitAnyIndexErrors": true,
        "preserveConstEnums": true,
        "outDir": "build"
    },
    "include": [
        "src/**/*"
    ]
}

How can I force it to pass through? ts-ignore all of them? Fixing those errors is not an option at the moment. Thanks.

`TS2354 This syntax requires an imported helper but module 'tslib' cannot be found.`

I see that the code has some references to tslib and importHelpers so I assume this should work transparently. If not, I'll be happy to know what is missing.

Here is how to reproduce:

Installed packages:

$ npm ls --depth=0
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

tsconfig.json:

{
    "compilerOptions": {
        "target": "es5"
    }
}

rollup.config.js:

import typescript from 'rollup-plugin-typescript2';

export default {
	entry: './main.ts',

	plugins: [
		typescript()
	]
}

main.ts:

import {Foo} from './module';

console.log("HERE" + Foo);

And module.ts:

export class Foo {}

export class Bar extends Foo {}

When running rollup as follows:

./node_modules/.bin/rollup -c rollup.config.js

I get this error:

🚨   rpt2: module.ts (3,18): semantic error TS2354 This syntax requires an imported helper but module 'tslib' cannot be found.
module.ts

I think this is because the extends syntax requires an __extends helper from tslib, but typescript can't find tslib.

Expected result is that the required helpers become part of the bundle.

Thanks.

Type only imports are not set as dependencies

After interface modification the plugin (v0.3.0) serves depending files from the cache, missing potentially breaking changes.

To reproduce make a clean build, break a type-only ts file and rerun a build.

When moving tsconfig, input path is not resolved to `cwd`

When I specify tsconfig other than root, such as:
tsconfig: "./config/tsconfig.json"

I start getting errors about my input parameter:

[!] (rpt2 plugin) Error: Could not find file: 'D:\Dev\test\src\main.ts'.

Note, D:\Dev\test\src\main.ts is where main.ts lives.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.