theseanl / tscc

A collection of tools to seamlessly bundle, minify Typescript with Closure Compiler
MIT License
161 stars 11 forks source link

Rollup plugin: TypeError: tscc is not a function #771

Open AlexLein opened 1 year ago

AlexLein commented 1 year ago

Hi, please excuse my ignorance,

I am trying to get tscc working by following the Getting Started guide in README.md, but I am running into an issue with the second phase (rollup). I have duplicated the folder structure from the example (mostly, I am building a library, not an Angular app). I am also using TypeScript instead of JavaScript.

my_project
├─package.json
├─rollup.config.ts
├─tscc.spec.json
├─tsconfig.json
└─src
    ├─foo.ts
    └─main.ts

I installed using npm instead of yarn, and if I execute tscc the project builds. I also removed the typescript() from the plugins in my rollup.config.ts file since it was not in the imports. And if I add an import for it, it has no effect.

>tscc
TSCC: Module option is set. tsickle converts TypeScript modules to Closure modulesvia CommonJS internally, so it will be overridden to "commonjs".
TSCC: tsickle uses a custom tslib optimized for closure compiler. importHelpers flag is set.
√ Closure Compiler 00:01
TSCC: Compilation success.

But when I get to also using rollup, it doesn't work and throws an error that tscc is not a command?

>rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript
[!] TypeError: tscc is not a function
TypeError: tscc is not a function
    at file:///x:/my_project/rollup.config-1666818813167.mjs:11:9
    at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:341:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async loadConfigFromWrittenFile (C:\Users\alein\AppData\Roaming\npm\node_modules\rollup\dist\shared\loadConfigFile.js:487:17)
    at async getConfigFileExport (C:\Users\alein\AppData\Roaming\npm\node_modules\rollup\dist\shared\loadConfigFile.js:410:20)
    at async Object.loadConfigFile (C:\Users\alein\AppData\Roaming\npm\node_modules\rollup\dist\shared\loadConfigFile.js:391:59)
    at async getConfigs (C:\Users\alein\AppData\Roaming\npm\node_modules\rollup\dist\bin\rollup:1680:39)
    at async runRollup (C:\Users\alein\AppData\Roaming\npm\node_modules\rollup\dist\bin\rollup:1657:43)

I have installed rollup, the rollup typescript plugin, tscc, the rollup plugin, all of them both locally and globally. I am hoping that I am missing something obvious, but this has been driving me nuts for two days.

Any idea what I am doing wrong, or is this really a bug?

smcjones commented 1 year ago

Maybe a rollup thing, but I got around it with tscc.default() instead of tscc()