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.

Compile failure with Next app using typescript functions from .ts file

See original GitHub issue

Prerequisites

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.

  1. Generate a Next.js app (nx g @nrwl/next:app myapp)
  2. Generate a utils workspace library (nx g @nrwl/workspace:lib utils --directory=mydirectory)
  3. Implement some utils function with TypeScript types in generated library
  4. 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:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tdnlcommented, Jan 7, 2020

Finally able to investigate the issue. Seems to be working, that was an easy fix 🙂

0reactions
tdnlcommented, Apr 19, 2022

Finally able to investigate the issue. Seems to be working, that was an easy fix 🙂

Your comment doesn’t make sense at all unless you let everyone know how did you fix that.

Have you tried looking at the pull request linked just above the message from 2020?

Read more comments on GitHub >

github_iconTop 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 >

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