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

TS 3.8 Unexpected token error -- Rollup doesn't understand ES2020 yet #213

Closed
negezor opened this issue Mar 7, 2020 · 2 comments
Closed
Labels
kind: support Asking for support with something or a specific use case scope: upstream Issue in upstream dependency solution: outdated This is not up-to-date with the current version solution: Rollup behavior This is Rollup's behavior and not specific to this plugin topic: TS version Related to a change in a TS version

Comments

@negezor
Copy link

negezor commented Mar 7, 2020

What happens and why it is wrong

I use rollup to build packages in monorepo. After upgrading from TypeScript 3.7.5 to 3.8.X, the assembly breaks with an error:

(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
packages/vk-io/src/utils/inspectable.ts: (12:37)
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
packages/vk-io/src/utils/inspectable.ts (12:37)
10: export interface IInspectableContext<P> {
11:   stylize: (text: string, color: 'special' | 'string') => string;
12:   inspect: (payload: P, options?: { compact?: boolean }) => string;
                                          ^
13: }
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (/home/negezor/projects/vk-io/node_modules/rollup/dist/shared/rollup.js:10116:30)
    at Module.error (/home/negezor/projects/vk-io/node_modules/rollup/dist/shared/rollup.js:14550:16)
    at tryParse (/home/negezor/projects/vk-io/node_modules/rollup/dist/shared/rollup.js:14443:23)
    at Module.setSource (/home/negezor/projects/vk-io/node_modules/rollup/dist/shared/rollup.js:14832:33)
    at /home/negezor/projects/vk-io/node_modules/rollup/dist/shared/rollup.js:16692:20
    at async Promise.all (index 12)
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at rollupInternal (/home/negezor/projects/vk-io/node_modules/rollup/dist/shared/rollup.js:18088:18)

Maybe I wasn't the only one who got that error.

Versions

  • typescript: 3.8.3
  • rollup: 2.0.2
  • rollup-plugin-typescript2: 0.26.0

rollup.config.js

/* eslint-disable import/no-extraneous-dependencies */
import jsonPlugin from 'rollup-plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
/* eslint-enable import/no-extraneous-dependencies */

import { tmpdir } from 'os';
// @ts-ignore
import { builtinModules } from 'module';
import { join as pathJoin } from 'path';

const MODULES = [
	'vk-io',
	'scenes',
	'session',
	'streaming',
	'authorization'
];

const coreModules = builtinModules.filter(name => (
	!/(^_|\/)/.test(name)
));

const cacheRoot = pathJoin(tmpdir(), '.rpt2_cache');

const getModulePath = path => (
	pathJoin(__dirname, 'packages', path)
);

// eslint-disable-next-line import/no-default-export
export default async function () {
	return Promise.all(
		MODULES
			.map(getModulePath)
			.map(async (modulePath) => {
				const modulePkg = await import(
					pathJoin(modulePath, 'package.json')
				);

				const src = pathJoin(modulePath, 'src');
				const lib = pathJoin(modulePath, 'lib');

				return {
					input: pathJoin(src, 'index.ts'),
					plugins: [
						jsonPlugin(),
						typescriptPlugin({
							cacheRoot,

							useTsconfigDeclarationDir: false,

							tsconfigOverride: {
								outDir: lib,
								rootDir: src,
								include: [src]
							}
						})
					],
					external: [
						...Object.keys(modulePkg.dependencies || {}),
						...Object.keys(modulePkg.peerDependencies || {}),
						// TODO: To make better
						...MODULES.map(moduleName => `@vk-io/${moduleName}`),
						...coreModules
					],
					output: [
						{
							file: pathJoin(modulePath, `${modulePkg.main}.js`),
							format: 'cjs',
							exports: 'named'
						},
						{
							file: pathJoin(modulePath, `${modulePkg.main}.mjs`),
							format: 'esm'
						}
					]
				};
			})
	);
}

tsconfig.json

{
	"compilerOptions": {
		"target": "ES2020",
		"module": "ESNext",
		"moduleResolution": "node",
		"strict": true,
		"noEmit": true,
		"declaration": true,
		"strictNullChecks": true,
		"forceConsistentCasingInFileNames": true
	}
}

package.json

{
	"name": "vk-io-monorepo",
	"private": true,
	"workspaces": [
		"packages/*"
	],
	"engines": {
		"node": ">=10.0.0"
	},
	"devDependencies": {
		"@types/jest": "^25.1.4",
		"@types/node": "^13.9.0",
		"@typescript-eslint/eslint-plugin": "^2.22.0",
		"@typescript-eslint/parser": "^2.22.0",
		"eslint": "^6.8.0",
		"eslint-config-airbnb-base": "^14.0.0",
		"eslint-plugin-import": "^2.20.1",
		"jest": "^25.1.0",
		"rollup": "^2.0.2",
		"rollup-plugin-json": "^4.0.0",
		"rollup-plugin-typescript2": "^0.26.0",
		"ts-jest": "^25.2.1",
		"typedoc": "^0.16.11",
		"typescript": "^3.8.3"
	},
	"scripts": {
		"rollup:build": "rollup -c rollup.config.js",
		"rollup:watch": "yarn run rollup:build -w"
	}
}

plugin output with verbosity 3

log:
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "inlineSourceMap": false,
    "outDir": "/tmp/.rpt2_cache/placeholder",
    "moduleResolution": 2,
    "allowNonTsExtensions": true,
    "declarationDir": "/home/negezor/projects/vk-io"
}
rpt2: parsed tsconfig: {
    "options": {
        "target": 7,
        "module": 99,
        "moduleResolution": 2,
        "strict": true,
        "noEmit": false,
        "declaration": true,
        "strictNullChecks": true,
        "forceConsistentCasingInFileNames": true,
        "configFilePath": "/home/negezor/projects/vk-io/tsconfig.json",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "inlineSourceMap": false,
        "outDir": "/tmp/.rpt2_cache/placeholder",
        "allowNonTsExtensions": true,
        "declarationDir": "/home/negezor/projects/vk-io"
    },
    "fileNames": [
        "/home/negezor/projects/vk-io/packages/vk-io/src/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/types.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/vk.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/api.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/manager.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/request.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/schemas/methods.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/schemas/objects.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/schemas/params.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/schemas/responses.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/workers/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/workers/parallel-selected.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/workers/parallel.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/workers/sequential.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/api/workers/worker.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/collect/chain.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/collect/collect.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/collect/execute-code.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/collect/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/collect/limits.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/collect/stream.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/api.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/collect.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/error.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/execute.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/snippets.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/updates.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/errors/upload.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/snippets/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/snippets/resource-resolver.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/snippets/snippets.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/attachment.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/audio-message.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/audio.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/document.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/external.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/gift.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/graffiti.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/helpers.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/link.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/market-album.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/market.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/photo.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/poll.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/sticker.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/story.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/video.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/wall-reply.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/attachments/wall.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/comment-action.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/context.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/dialog-flags.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/group-member.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/group-update.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/group-user.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/message-allow.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/message-flags.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/message.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/new-attachments.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/read-messages.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/removed-messages.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/typing.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/user-online.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/vk-app-payload.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/vk-pay-transaction.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/vote.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/contexts/wall-post.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/keyboard/builder.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/keyboard/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/keyboard/keyboard.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/keyboard/types.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/shared/attachmentable.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/shared/composer.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/shared/message-forward.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/shared/message-forwards-collection.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/structures/shared/message-reply.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/updates/helpers.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/updates/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/updates/transform-message.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/updates/updates.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/updates/transports/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/updates/transports/polling.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/updates/transports/webhook.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/upload/helpers.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/upload/index.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/upload/multipart-stream.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/upload/upload.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/utils/callback-service.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/utils/constants.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/utils/helpers.ts",
        "/home/negezor/projects/vk-io/packages/vk-io/src/utils/inspectable.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "target": "ES2020",
            "module": "ESNext",
            "moduleResolution": "node",
            "strict": true,
            "noEmit": true,
            "declaration": true,
            "strictNullChecks": true,
            "forceConsistentCasingInFileNames": true
        },
        "outDir": "/home/negezor/projects/vk-io/packages/vk-io/lib",
        "rootDir": "/home/negezor/projects/vk-io/packages/vk-io/src",
        "include": [
            "/home/negezor/projects/vk-io/packages/vk-io/src"
        ],
        "compileOnSave": false
    },
    "errors": [],
    "wildcardDirectories": {
        "/home/negezor/projects/vk-io/packages/vk-io/src": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "/home/negezor/projects/vk-io/packages/vk-io/src"
        ],
        "validatedIncludeSpecs": [
            "/home/negezor/projects/vk-io/packages/vk-io/src"
        ],
        "wildcardDirectories": {
            "/home/negezor/projects/vk-io/packages/vk-io/src": 1
        }
    }
}
rpt2: typescript version: 3.8.3
rpt2: tslib version: 1.10.0
rpt2: rollup version: 2.0.2
rpt2: rollup-plugin-typescript2 version: 0.26.0
rpt2: plugin options:
{
    "cacheRoot": "/tmp/.rpt2_cache",
    "verbosity": 3,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {
        "outDir": "/home/negezor/projects/vk-io/packages/vk-io/lib",
        "rootDir": "/home/negezor/projects/vk-io/packages/vk-io/src",
        "include": [
            "/home/negezor/projects/vk-io/packages/vk-io/src"
        ]
    },
    "check": true,
    "clean": false,
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false,
    "cwd": "/home/negezor/projects/vk-io",
    "typescript": "version 3.8.3"
}
rpt2: rollup config:
{
    "experimentalCacheExpiry": 10,
    "external": [
        "abort-controller",
        "debug",
        "middleware-io",
        "node-fetch",
        "sandwich-stream",
        "@vk-io/vk-io",
        "@vk-io/scenes",
        "@vk-io/session",
        "@vk-io/streaming",
        "@vk-io/authorization",
        "assert",
        "async_hooks",
        "buffer",
        "child_process",
        "cluster",
        "console",
        "constants",
        "crypto",
        "dgram",
        "dns",
        "domain",
        "events",
        "fs",
        "http",
        "http2",
        "https",
        "inspector",
        "module",
        "net",
        "os",
        "path",
        "perf_hooks",
        "process",
        "punycode",
        "querystring",
        "readline",
        "repl",
        "stream",
        "string_decoder",
        "sys",
        "timers",
        "tls",
        "trace_events",
        "tty",
        "url",
        "util",
        "v8",
        "vm",
        "worker_threads",
        "zlib"
    ],
    "inlineDynamicImports": false,
    "input": "/home/negezor/projects/vk-io/packages/vk-io/src/index.ts",
    "perf": false,
    "plugins": [
        {
            "name": "json"
        },
        {
            "name": "rpt2"
        },
        {
            "name": "stdin"
        }
    ],
    "strictDeprecations": false
}
rpt2: tsconfig path: /home/negezor/projects/vk-io/tsconfig.json
rpt2: included:
[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]
rpt2: excluded:
[
    "*.d.ts",
    "**/*.d.ts"
]
@negezor
Copy link
Author

negezor commented Mar 7, 2020

Decision to downgrade target version in compilerOptions to ES2019.

@negezor negezor closed this as completed Mar 7, 2020
@ezolenko
Copy link
Owner

Yeah, this was rollup or one of its dependencies not understanding resulting js.

@agilgur5 agilgur5 added kind: support Asking for support with something or a specific use case solution: out-of-scope This is out of scope for this project scope: upstream Issue in upstream dependency topic: TS version Related to a change in a TS version labels Apr 29, 2022
@agilgur5 agilgur5 changed the title TypeScript 3.8.X breaks the assembly TS 3.8 Unexpected token error -- Rollup doesn't understand ES2020 yet Apr 29, 2022
Repository owner locked as resolved and limited conversation to collaborators Apr 29, 2022
@agilgur5 agilgur5 added the solution: outdated This is not up-to-date with the current version label May 2, 2022
@agilgur5 agilgur5 added solution: Rollup behavior This is Rollup's behavior and not specific to this plugin and removed solution: out-of-scope This is out of scope for this project labels Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: support Asking for support with something or a specific use case scope: upstream Issue in upstream dependency solution: outdated This is not up-to-date with the current version solution: Rollup behavior This is Rollup's behavior and not specific to this plugin topic: TS version Related to a change in a TS version
Projects
None yet
Development

No branches or pull requests

3 participants