Unexpected token when importing from dependency written in TypeScript
See original GitHub issueBug 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:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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) .
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.