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

Fails to compile .js file to es5? -- set plugin include #150

Closed
yavorski opened this issue May 16, 2019 · 2 comments
Closed

Fails to compile .js file to es5? -- set plugin include #150

yavorski opened this issue May 16, 2019 · 2 comments
Labels
kind: support Asking for support with something or a specific use case solution: already possible This is already possible / this feature already exists

Comments

@yavorski
Copy link

What happens and why it is wrong

I have a project with mixed .js, .mjs and .ts files which all should compile down to es5.
What is going wrong is that the plugin is compiling only files with the .ts extensions.
Is it possible to compile the .js files too?
I already set "allowJs": true in tsconfig.json.

Here is a test repository reproducing the issue ->
https://github.com/yavorski/rollup-typescript-fail-js.

As you can see in the compiled file async/await is not compiled...

Any advance would be helpfull.

Environment

  • Arch
  • Debian
  • Windows

Versions

  • typescript@latest
  • rollup@latest
  • rollup-plugin-typescript2@latest

rollup.config.js

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

const config = {
  input: 'index.js',
  output: {
    format: 'iife',
    sourcemap: false,
    file: 'compiled.js',
  },
  plugins: [
    resolve(),
    commonjs(),
    typescript()
  ],
  watch: {
    chokidar: false,
    clearScreen: false,
    include: './src/js/**',
    exclude: 'node_modules/**'
  }
};

export default config;

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "lib": ["es5", "es6", "dom"],
    "allowJs": true,
    "checkJs": true,
    "strict": true,
    "esModuleInterop": true
  },
  "include": [
    "index.js"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

package.json

{
  "name": "rollup-typescript-fail",
  "version": "1.0.0",
  "description": "Rollup Typescript fails to compile .js files",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {},
  "devDependencies": {
    "rollup": "1.12.1",
    "rollup-plugin-commonjs": "10.0.0",
    "rollup-plugin-node-resolve": "5.0.0",
    "rollup-plugin-typescript2": "0.21.0",
    "typescript": "3.4.5"
  },
  "scripts": {
    "build": "rollup --config rollup.config.js"
  }
}

plugin output with verbosity 3

$ npm run build

> [email protected] build ~/dev/rollup-typescript-fail-js
> rollup --config rollup.config.js

index.js → compiled.js...
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "inlineSourceMap": false,
    "outDir": "~/dev/rollup-typescript-fail-js/.rpt2_cache/placeholder",
    "moduleResolution": 2,
    "allowNonTsExtensions": true
}
rpt2: parsed tsconfig: {
    "options": {
        "target": 1,
        "module": 5,
        "lib": [
            "lib.es5.d.ts",
            "lib.es2015.d.ts",
            "lib.dom.d.ts"
        ],
        "allowJs": true,
        "checkJs": true,
        "strict": true,
        "esModuleInterop": true,
        "configFilePath": "~/dev/rollup-typescript-fail-js/tsconfig.json",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "inlineSourceMap": false,
        "outDir": "~/dev/rollup-typescript-fail-js/.rpt2_cache/placeholder",
        "moduleResolution": 2,
        "allowNonTsExtensions": true
    },
    "fileNames": [
        "~/dev/rollup-typescript-fail-js/index.js"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "target": "es5",
            "module": "es2015",
            "lib": [
                "es5",
                "es6",
                "dom"
            ],
            "allowJs": true,
            "checkJs": true,
            "strict": true,
            "esModuleInterop": true
        },
        "include": [
            "index.js"
        ],
        "exclude": [
            "node_modules",
            "**/*.spec.ts"
        ],
        "compileOnSave": false
    },
    "errors": [],
    "wildcardDirectories": {},
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "index.js"
        ],
        "excludeSpecs": [
            "node_modules",
            "**/*.spec.ts"
        ],
        "validatedIncludeSpecs": [
            "index.js"
        ],
        "validatedExcludeSpecs": [
            "node_modules",
            "**/*.spec.ts"
        ],
        "wildcardDirectories": {}
    }
}
rpt2: typescript version: 3.4.5
rpt2: tslib version: 1.9.3
rpt2: rollup version: 1.12.1
rpt2: rollup-plugin-typescript2 version: 0.21.0
rpt2: plugin options:
{
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "~/dev/rollup-typescript-fail-js/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false,
    "typescript": "version 3.4.5"
}
rpt2: rollup config:
{
    "chunkGroupingSize": 5000,
    "experimentalCacheExpiry": 10,
    "external": [],
    "inlineDynamicImports": false,
    "input": "index.js",
    "perf": false,
    "plugins": [
        {
            "name": "node-resolve"
        },
        {
            "name": "commonjs"
        },
        {
            "name": "rpt2"
        }
    ],
    "watch": {
        "chokidar": false,
        "clearScreen": false,
        "include": "./src/js/**",
        "exclude": "node_modules/**"
    }
}
rpt2: tsconfig path: ~/dev/rollup-typescript-fail-js/tsconfig.json
rpt2: included:
[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]
rpt2: excluded:
[
    "*.d.ts",
    "**/*.d.ts"
]
rpt2: generating target 1
rpt2: Ambient types:
rpt2:     ~/dev/rollup-typescript-fail-js/node_modules/@types/estree/index.d.ts
rpt2:     ~/dev/rollup-typescript-fail-js/node_modules/@types/node/ts3.2/index.d.ts
rpt2:     ~/dev/rollup-typescript-fail-js/node_modules/@types/resolve/index.d.ts
rpt2: rolling caches
created compiled.js in 1.8s

As I said, any advice would be helpful.
Thanks in advance!

@ezolenko
Copy link
Owner

ezolenko commented May 17, 2019

@yavorski Check out include option, by default it is only processing ts and tsx: [ "*.ts+(|x)", "**/*.ts+(|x)" ]

typescript({ include: [ "*.ts+(|x)", "**/*.ts+(|x)", "*.js", "*.mjs" ] })

@yavorski
Copy link
Author

10x

@agilgur5 agilgur5 changed the title Fails to compile .js file to es5? Fails to compile .js file to es5? -- set plugin include May 21, 2022
@agilgur5 agilgur5 added kind: support Asking for support with something or a specific use case solution: already possible This is already possible / this feature already exists labels May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case solution: already possible This is already possible / this feature already exists
Projects
None yet
Development

No branches or pull requests

3 participants