Rollup build typescrit error 'Unexpected token'

Viewed 3157

I have a typescript project which I try to build with rollup and @rollup/plugin-typescript. The project builds except when I import the module "../src/lib/pages".

The repo for reproduction is available here: https://github.com/igorovic/mangoost

The issue occurs in the file: cli/cli.ts.

The Error

[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/lib/filesystem.ts (4:29)
2: import path from 'path';
3: 
4: export function WalkSync(Path: string, prefix?: string, options={ignoreDirs: false}){
                                ^
5:     let Files: string[] = [];
6:     let Listing = fs.readdirSync(Path, {withFileTypes: true});
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:5195:30)
    at Module.error (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:9676:16)
    at tryParse (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:9590:23)
    at Module.setSource (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:9982:30)
    at ModuleLoader.addModuleSource (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:18101:20)
    at async ModuleLoader.fetchModule (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:18155:9)
    at async Promise.all (index 1)
    at async ModuleLoader.fetchStaticDependencies (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:18179:34)
    at async Promise.all (index 0)
    at async ModuleLoader.fetchModule (/Users/gor00/DEV/mangoost/node_modules/rollup/dist/shared/rollup.js:18156:9)

How to reproduce

Uncomment the lines in cli/cli.ts

//import { pages } from '../src/lib/pages';
//console.log(pages());

Run npm run build

After a whole day searching everywhere I did not find any hint on what may cause this error.

1 Answers

Eventually I fixed my problem by using two separate tsconfig.json one to build the bundle with Rollup and another one to transpile the *.ts files with typescript tsccli tool.

The main issue was to understand that @rollup/plugin-typescript configuration option inlude is not related to the tsconfig.json option include. It's used for some internal mechanism I have not digged in.

Related