Typescript plugin 4.0.0 Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

See original GitHub issue
  • Rollup Plugin Name: typescript
  • Rollup Plugin Version: 4.0.0
  • Rollup Version: 2.2.0
  • Operating System (or Browser): macOsx
  • Node Version: 10.16.3

How Do We Reproduce?

import tsPlugin from '@rollup/plugin-typescript';
import pkg from './package.json';

export default {
	input: 'src/index.tsx',
	output: [
		{
			file: pkg.main,
			format: 'cjs',
			sourcemap: true,
		},
		{
			file: pkg.module,
			format: 'es',
			sourcemap: true,
		},
	],
	plugins: [
		tsPlugin(),
	],
};

Expected Behavior

src/index.tsx → dist/index.js, dist/index.es.js...
created dist/index.js, dist/index.es.js in 1.1s

Actual Behavior

[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/index.tsx (1:25)
1: export function hasan(num: number): number {
                            ^

I hope I’m doing something wrong because it is so bad to cant use ts plugin. Ts plugin version 3.0.0 works perfect by the way.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:136
  • Comments:65 (15 by maintainers)

github_iconTop GitHub Comments

48reactions
sssylvancommented, Mar 30, 2020

Quick fix for now is to manually set your rootDir compiler option to “src”.

44reactions
huww98commented, Apr 9, 2020

@talentlessguy I resolved this problem by removing outDir, declarationDir, declaration from tsconfig.json. If you need them when you invoke tsc, specify them using command line arguments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token (Note that you need plugins to import files ...
Building Typescript: [!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) ; config.js stderr ; config....
Read more >
rollup/plugin-typescript/README.md - UNPKG
168, [!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript). 169, file.tsx (1:15).
Read more >
@rollup/plugin-typescript - npm package | Snyk
Error : Unexpected token (Note that you need plugins to import files that are not JavaScript) file.tsx (1:15) 1: export default <span>Foobar</span> ^....
Read more >
@rollup/plugin-typescript - npm
Seamless integration between Rollup and TypeScript. ... Start using @rollup/plugin-typescript in your project by running `npm i ...
Read more >
Getting a TypeScript enum in a standalone file to play nice ...
The error message is telling you that you need a plugin that can handle .ts files, so you need to add the typescript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found