Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outDir set to process.cwd() cause TS5055 error easily #83

Closed
grayflow opened this issue Jun 5, 2018 · 9 comments
Closed

outDir set to process.cwd() cause TS5055 error easily #83

grayflow opened this issue Jun 5, 2018 · 9 comments
Labels
scope: upstream Issue in upstream dependency

Comments

@grayflow
Copy link

grayflow commented Jun 5, 2018

What happens and why it is wrong

Environment

Versions

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

rollup.config.js

import commonjs from "rollup-plugin-commonjs";
import json from 'rollup-plugin-json';
import resolve from "rollup-plugin-node-resolve";

import ts from "typescript";

import typescript from "rollup-plugin-typescript2";

export default {
    input: 'src/main.ts',
    output: {
        file: 'bin/js/bundle.js',
        format: 'iife',
        strict: true,
        sourcemap: true,
    },
    plugins: [
        json({
        }),
        resolve(),
        commonjs(),

        typescript({
            typescript: ts,
            verbosity: 3
        }),
    ]
};

tsconfig.json

{
  "compilerOptions": {
    "charset": "utf8",
    "locale": "zh-CN",
    "module": "es2015",
    "target": "es5",
    "baseUrl": ".",

    "moduleResolution": "node",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "noEmitOnError": true,
    "sourceMap": true,
    "diagnostics": true
  },
  "include": [
    "src",
    "json",
    "LayaAir/LayaAir.d.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

package.json

plugin output with verbosity 3

yarn run v1.7.0
$ rollup -c rollup.config.js

src/main.ts → bin/js/bundle.js...
rpt2: typescript version: 2.9.1
rpt2: rollup-plugin-typescript2 version: 0.14.0
rpt2: plugin options:
{
    "typescript": "version 2.9.1",
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "/Users/gray/projects/LayaTemplates/1.7.19beta/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {}
}
rpt2: rollup config:
{
    "external": [
        "",
        ""
    ],
    "input": "src/main.ts",
    "chunkGroupingSize": 5000,
    "perf": false,
    "plugins": [
        {
            "name": "json"
        },
        {
            "name": "node-resolve"
        },
        {
            "name": "commonjs"
        },
        {
            "name": "rpt2"
        }
    ],
    "entry": "src/main.ts"
}
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "inlineSourceMap": false,
    "outDir": "/Users/gray/projects/LayaTemplates/1.7.19beta",
    "moduleResolution": 2,
    "declarationDir": null
}
rpt2: parsed tsconfig: {
    "options": {
        "module": 5,
        "charset": "utf8",
        "locale": "zh-CN",
        "target": 1,
        "baseUrl": "/Users/gray/projects/LayaTemplates/1.7.19beta",
        "moduleResolution": 2,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "forceConsistentCasingInFileNames": true,
        "noEmitOnError": true,
        "sourceMap": true,
        "diagnostics": true,
        "configFilePath": "/Users/gray/projects/LayaTemplates/1.7.19beta/tsconfig.json",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "inlineSourceMap": false,
        "outDir": "/Users/gray/projects/LayaTemplates/1.7.19beta",
        "declarationDir": null
    },
    "fileNames": [
        "/Users/gray/projects/LayaTemplates/1.7.19beta/src/main.ts",
        "/Users/gray/projects/LayaTemplates/1.7.19beta/LayaAir/LayaAir.d.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "module": "es2015",
            "charset": "utf8",
            "locale": "zh-CN",
            "target": "es5",
            "baseUrl": ".",
            "moduleResolution": "node",
            "resolveJsonModule": true,
            "esModuleInterop": true,
            "allowSyntheticDefaultImports": true,
            "forceConsistentCasingInFileNames": true,
            "noEmitOnError": true,
            "sourceMap": true,
            "diagnostics": true
        },
        "include": [
            "src",
            "json",
            "LayaAir/LayaAir.d.ts"
        ],
        "exclude": [
            "node_modules",
            "json"
        ]
    },
    "errors": [],
    "wildcardDirectories": {},
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "src",
            "json",
            "LayaAir/LayaAir.d.ts"
        ],
        "excludeSpecs": [
            "node_modules",
            "json"
        ],
        "validatedIncludeSpecs": [
            "src",
            "json",
            "LayaAir/LayaAir.d.ts"
        ],
        "validatedExcludeSpecs": [
            "node_modules",
            "json"
        ],
        "wildcardDirectories": {}
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: options error TS5055 Cannot write file '/Users/gray/projects/LayaTemplates/1.7.19beta/json/a.json' because it would overwrite input file.
rpt2: Ambient types:
rpt2:     /Users/gray/projects/LayaTemplates/1.7.19beta/LayaAir/LayaAir.d.ts
rpt2:     /Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/@types/estree/index.d.ts
rpt2:     /Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/@types/node/index.d.ts
rpt2: transpiling '/Users/gray/projects/LayaTemplates/1.7.19beta/src/main.ts'
rpt2:     cache: '/Users/gray/projects/LayaTemplates/1.7.19beta/.rpt2_cache/60d02db33c5a1f3b2416647a31884b4a2a666d0d/code/cache/8fa213cd863a0deec8ed932ab96e42abc1472537'
rpt2:     cache miss
rpt2:     cache: '/Users/gray/projects/LayaTemplates/1.7.19beta/.rpt2_cache/60d02db33c5a1f3b2416647a31884b4a2a666d0d/syntacticDiagnostics/cache/8fa213cd863a0deec8ed932ab96e42abc1472537'
rpt2:     cache hit
rpt2:     cache: '/Users/gray/projects/LayaTemplates/1.7.19beta/.rpt2_cache/60d02db33c5a1f3b2416647a31884b4a2a666d0d/semanticDiagnostics/cache/8fa213cd863a0deec8ed932ab96e42abc1472537'
rpt2:     cache hit
rpt2: rolling caches
[!] (rpt2 plugin) Error: failed to transpile '/Users/gray/projects/LayaTemplates/1.7.19beta/src/main.ts'
src/main.ts
Error: failed to transpile '/Users/gray/projects/LayaTemplates/1.7.19beta/src/main.ts'
    at error (/Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/rollup/dist/rollup.js:199:15)
    at Object.error (/Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/rollup/dist/rollup.js:17550:21)
    at /Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:20162:31
    at TsCache.getCompiled (/Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:19817:31)
    at Object.transform (/Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:20148:34)
    at /Users/gray/projects/LayaTemplates/1.7.19beta/node_modules/rollup/dist/rollup.js:17555:48
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:746:11)
    at startup (internal/bootstrap/node.js:238:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@grayflow
Copy link
Author

grayflow commented Jun 5, 2018

simply change
outDir: process.cwd()
to
outDir: process.cwd() + '/build'
in get-options-overrides.ts would fix the problem

@ezolenko
Copy link
Owner

ezolenko commented Jun 5, 2018

This is by design -- typescript refuses to overwrite input files by output files so you don't destroy all your source code :)

@ezolenko ezolenko closed this as completed Jun 5, 2018
@grayflow
Copy link
Author

grayflow commented Jun 6, 2018

@ezolenko , but TypeScript 2.9 support import json file as es6 module now

@grayflow
Copy link
Author

grayflow commented Jun 6, 2018

may be it's a typescript bug microsoft/TypeScript#24715

@ezolenko ezolenko reopened this Jun 6, 2018
@ezolenko
Copy link
Owner

ezolenko commented Jun 6, 2018

nvm, I'll do a workaround -- it works as intended if you use tsc directly, but shouldn't trip the plugin up.

@ezolenko
Copy link
Owner

ezolenko commented Jun 6, 2018

@grayflow I added your workaround, check if master works for you

@grayflow
Copy link
Author

grayflow commented Jun 7, 2018

@ezolenko , it works

@grayflow grayflow closed this as completed Jun 7, 2018
@grayflow
Copy link
Author

grayflow commented Jun 7, 2018

@ezolenko , another problem: rollup-plugin-typescript2 would not respect mapRoot option in tsconfig.json

@ezolenko
Copy link
Owner

ezolenko commented Jun 7, 2018

@grayflow I don't think I can respect mapRoot -- I'm not writing out maps myself, I give them to rollup and it meshes them with maps generated by other plugins on the chain and then generates its own mapping for the bundle. For example if you add uglify plugin, maps will go ts -> plain js -> uglified js -> bundled js (not sure about the order of the last two)

@agilgur5 agilgur5 changed the title outDir set to process.cwd() cause TS5055 error easily outDir set to process.cwd() cause TS5055 error easily May 22, 2022
@agilgur5 agilgur5 added the scope: upstream Issue in upstream dependency label May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: upstream Issue in upstream dependency
Projects
None yet
Development

No branches or pull requests

3 participants