Skip to content

Including .js files in input causes "error TS5055: Cannot write file '_filename.js_' because it would overwrite input file." #768

Open
@cpcallen

Description

@cpcallen

I'm trying to establish if tscc would be a suitable tool for building Blockly, which is currently built using tsc and Closure Compiler (running in SIMPLE_OPTIMIZATIONS mode in part due to incompatibility between tsc output for enum and Closure Compiler's prohibition on quoting property names—presumably one of the motivations for the creation of tscikle in the first place).

At the moment I have checked out our develop branch and am trying to compile our advanced compilation test (which verifies that Blockly can be built using ADVANCED_OPTIMIZATIONS) by modifying our tsconfig.json to:

{
  "include": [
    "core/**/*",
    "closure/**/*",
    "tests/compile/**/*", // Added for advanced compilation test.
  ],
  "exclude": [
    "core/blockly.js"
  ],
  "compilerOptions": {
    "allowJs": true,
    "sourceMap": true,
    "module": "ES2015",
    "moduleResolution": "node",
    "target": "ES2020",
    "strict": true,
  }
}

and added a simple tscc.spec.json:

{
  "modules": {
    "out": "tests/compile/main.js"
  },
  "prefix": "build/"
}

Unfortunately, running tscc generates errors for each .js file included in the build:

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.
TS: error TS5055: Cannot write file '/Users/cpcallen/src/blockly/closure/goog/base.js' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cpcallen/src/blockly/closure/goog/base_minimal.js' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cpcallen/src/blockly/closure/goog/goog.js' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cpcallen/src/blockly/core/main.js' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cpcallen/src/blockly/tests/compile/main.js' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cpcallen/src/blockly/tests/compile/main_compressed.js' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cpcallen/src/blockly/tests/compile/test_blocks.js' because it would overwrite input file.
node_modules/@types/node/globals.d.ts(42,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'gc' must be of type 'cc', but here has type '(() => void) | undefined'.

TSCC: The compilation has terminated with an error.

I tired using tsc's -outputDir` flag, but this just generated a warning that it was ignored:

$ npx tscc -- -outDir build/src
TSCC: Module option is set. tsickle converts TypeScript modules to Closure modulesvia CommonJS internally, so it will be overridden to "commonjs".
TSCC: --outDir option is set, but it is no-op for tscc.Use prefix option in spec file to control output directory.
...

which is why I added the prefix directive totscc.spec.json. But it appears that prefix is applied only to the output of closure compiler, not the output of tsc.

How can I build a project containing a mix of .ts and .js input files? Given that base.js is mandatory for Closure-based projects, this is presumably supported somehow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions