question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected token when importing from dependency written in TypeScript

See original GitHub issue

Bug report

Describe the bug

I have just started transitioning an existing webapp to Next.js. Our current setup is bundled and deployed via rollup. We have a dependency which is an API client written in TypeScript, which is not transpiled until our app is bundled. I was under the impression that Next.js would handle this automatically, but it seems to be running into a problem. When I load my app, I get this error:

./node_modules/@kalos-core/kalos-rpc/Event/index.ts 12:20
Module parse failed: Unexpected token (12:20)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| class EventClient extends BaseClient {
>   constructor(userID: number, host?: string) {
|     super(userID, host);
|   }

I’m guessing I need to add a custom webpack config with ts-loader? But I’m a bit confused since my components are also written in TypeScript and they don’t throw errors.

Expected behavior

Next.js to transpile my dependencies

System information

  • OS: [macOS]
  • Browser (if applies) [chrome]
  • Version of Next.js: [9.2.1]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jamesmosiercommented, Feb 12, 2020

Next does not transpile any third party node modules. Also any typescript files outside of the your main application source directory will not be transpiled either (see #9474 for more info on this one) .

0reactions
balazsorban44commented, Jan 30, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token when importing from dependency written in ...
We have a dependency which is an API client written in TypeScript, ... Unexpected token when importing from dependency written in TypeScript ......
Read more >
Unexpected token export es6 dependency in ts project
When i try to run this code using ts-node <path/to/my/index. ts> (entry point of my typescript project), i get an unexpected token 'export'...
Read more >
syntaxerror unexpected token 'export' typescript - You.com
So the dependency in node_modules folder exports a function using ES6 import/export module. The code will throw error when it running in browser...
Read more >
unexpected token "export" when importing a library -500 error
When importing my library - which loads a dependency library called Ionic, I get the error 'unexpected token export'.
Read more >
Unexpected token import Error in TypeScript | bobbyhadz
To solve the Uncaught SyntaxError: Unexpected token import in TypeScript, set the `module` option to `commonjs` in your `tsconfig.json` file and make sure ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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 Reddit Thread

No results found

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