Compile failure with Next app using typescript functions from .ts file
See original GitHub issuePrerequisites
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
- I am running the latest version
- I checked the documentation (nx.dev) and found no answer
- I checked to make sure that this issue has not already been filed
- I’m reporting the issue to the correct repository (not related to React, Angular or any dependency)
Expected Behavior
Next app page should render using utils functions from a .ts file.
Current Behavior
The page displays a “Failed to compile” error
Failure Information (for bugs)
/Users/thomas/GitHub/myorg/libs/mydirectory/utils/src/lib/mydirectory-utils.ts 1:24
Module parse failed: Unexpected token (1:24)
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
> export function random(): number {
| return Math.round(Math.random() * 10);
| }
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- Generate a Next.js app (
nx g @nrwl/next:app myapp) - Generate a utils workspace library (
nx g @nrwl/workspace:lib utils --directory=mydirectory) - Implement some utils function with TypeScript types in generated library
- Use util function in next app page.
Here is a repository with an example: https://github.com/tdnl/nx-test
After cloning and installing the dependencies, run nx serve myapp to see the error.
Note that if we rename the utils file from .ts to .tsx, the page will load correctly.
Context
Please provide any relevant information about your setup:
@nrwl/angular : Not Found
@nrwl/cli : 8.9.0
@nrwl/cypress : 8.9.0
@nrwl/eslint-plugin-nx : 8.9.0
@nrwl/express : Not Found
@nrwl/jest : 8.9.0
@nrwl/linter : 8.9.0
@nrwl/nest : Not Found
@nrwl/next : 8.9.0
@nrwl/node : Not Found
@nrwl/react : 8.9.0
@nrwl/schematics : Not Found
@nrwl/tao : 8.9.0
@nrwl/web : 8.9.0
@nrwl/workspace : 8.9.0
typescript : 3.5.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Basic Features: TypeScript - Next.js
Next.js fails your production build ( next build ) when TypeScript errors are present in your project. If you'd like Next.js to dangerously...
Read more >Build errors in my next.js app after upgrading to 12.#.# and ...
I needed to run yarn add --dev @typescript-eslint/parser @typescript-eslint/eslint-plugin. and add this to eslintrc.js.
Read more >Using Next.js with TypeScript - LogRocket Blog
In this tutorial, learn how to use Next.js with TypeScript to build a modern stack for high-quality, search-optimized apps.
Read more >A Guide for Next.js with TypeScript - Refine Dev
If you happen to have TypeScript errors while running next build , Next.js will fail the build but you can disable the type...
Read more >isolatedModules - TSConfig Option - TypeScript
... applies to TypeScript's ts.transpileModule API which is used by some build tools. ... An error occurs if any file isn't a module:...
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 Free
Top 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

Finally able to investigate the issue. Seems to be working, that was an easy fix 🙂
Have you tried looking at the pull request linked just above the message from 2020?