Combine Typescript files from a dependent module to aid in debugging within a Next.js application

Trying to debug a project written in Typescript using Next.js, but facing issues with bundling TS files from a local dependent common library. Only JS files are included, which is not sufficient for debugging.

The goal is to bundle all TS files from the workspace with webpack and enable source mapping for debugging in Chrome Dev Tools.

It's strange that only the compiled code of index.tsx from the ./pages folder is included in the bundle, not the actual TS file.

Utilized:

  • Next.js 6.1.1
  • Typescript 3.8.3
  • es5

next.config.js

const withTypescript = require('@zeit/next-typescript')
module.exports = withTypescript({
    poweredByHeader: false,
    webpack: (config, {dev}) => {
        if (dev) {
            config.devtool = 'inline-source-map';
            config.resolve.extensions = ['.ts', '.tsx', '.js', '.jsx', '.json'];
            config.output.sourceMapFilename = "[name].js.map";
        }

        return config;
    },
    distDir: '../dist',
});

.babelrc

"presets": [
    "next/babel",
    "@zeit/next-typescript/babel"
  ]
}

app package.json

{
      "name": "project",
      "version": "0.0.1",
      "license": "UNLICENSED",
      "private": true,
      "description": "The project",
      "author": "author <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed8c989985829fad88958c809d8188c38e8280">[email protected]</a>>",
      "browserslist": [
        "> 0.5%",
        "last 2 versions"
      ],
      "nodemonConfig": {
        "ignoreRoot": [
          ".git"
        ],
        "watch": [
          "src/server.js"
        ]
      },
      "dependencies": {
        "@project/common": "*"
      },
      "devDependencies": {
        "@zeit/next-typescript": "1.1.0"
      }
    }

common lib package.json

{
  "name": "@project/common",
  "version": "1.0.0",
  "license": "UNLICENSED",
  "main": "build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "build/*"
  ],
  ... (additional content shortened for brevity)
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es5", "es2015.promise", "dom"],
    ... (additional properties omitted for brevity)
  }
}

Answer №1

After reviewing your query, it seems there may be some confusion between declaration files and source maps. Let me clarify the differences between the two:

  • Declarations
  • Declaration Maps
  • Source Maps

Declaration files, identified by the d.ts extension, define the types of an exported TypeScript project and are utilized by TypeScript itself. These files are not related to browser functionality. When publishing a TypeScript project on NPM, it is typically compiled into JavaScript for compatibility with plain JavaScript projects. However, to retain TypeScript's typization benefits, declaration maps come into play as they outline the type information in the underlying JavaScript code.

Source Maps serve as tools to deconstruct minified JavaScript for debugging purposes. While not directly associated with TypeScript, if the described JavaScript is generated by the TypeScript compiler, exporting source maps can help in explaining the minified code. This way, the compiler provides insights into the minified code structure.

Declaration files primarily provide an interface for other TypeScript modules/projects to properly integrate your library without revealing the complete source code for debugging. For debugging accessibility, developers require Declaration Maps. Similar to Source Maps, Declaration Maps illustrate the original TypeScript instead of expanding minified JavaScript, enabling debugging of pre-compiled libraries as if they were TypeScript code.

To activate these features, adjustments must be made in your libraries tsconfig.json file by including one or more of the following configurations:

"declaration": true,
"declarationMap": true,
"sourceMap": true

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using framer-motion with Next.js, it will smoothly animate from 0vh to 100vh, but it struggles to animate from -100vh to 0vh

I have been working on animating a navbar to open and close, but I'm encountering an issue. I have a larger container that changes height during the animation, and I want to simultaneously slide down an inner container as it adjusts its height. The pr ...

ANGULAR: Issue with filtering an array by clicking a button is not functioning

I've been attempting to apply a filter to my array by using modulo on the id when clicking multiple buttons. I initially tried using pipe but was advised to stick with .filter(). Despite watching numerous online tutorials, I keep encountering errors o ...

Instructions on transferring JSON data to clipboard using a button

How can I copy JSON data to clipboard using a button click? { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ ... ], "Resource": "*" } ] } I attempted to ...

Encountered a 404 error (not found) while making a GET request with axios

I encountered an issue with my pizza shop application built with Next.js. Whenever I run the app on my computer, I come across this error: https://i.sstatic.net/tsQzZ.png The error disappears after refreshing the page. Here is my index.js file: import ax ...

The "response" body should have an "access_token" property that is a string of characters and not empty

I am encountering an issue with my Next.js app that utilizes next-auth and the GitHub provider. I have created a new GitHub OAuth app and obtained the Client ID and Client Secret. Following the steps outlined in the next-auth documentation: Upon clicking ...

a helpful utility type for extracting a union from a constant array of strings

I create string arrays using const assertions and then use them to generate union types. const elements = ["apple", "banana", "orange"] as const; type elementsUnion = typeof elements[number]; // type elementsUnion = "appl ...

The 'ngModel' property cannot be bound to a 'textarea' element because it is not recognized as a valid property

When I run Karma with Jasmine tests, I encounter the following error message: The issue is that 'ngModel' cannot be bound since it is not recognized as a property of 'textarea'. Even though I have imported FormsModule into my app.modu ...

Encounter internal server error (500) while using Next.js and React

Currently, I am creating a website for a college project without much prior coding experience. I followed a tutorial on YouTube to help me with the development process. When running the site locally, it seems to "work" as intended. However, upon initial ex ...

"Encountering the error of 'require is not defined' in an Electron-React-Webpack-Typescript application when utilizing

When I add these lines to /src/renderer.ts in an Electron-React-Webpack-Typescript app: ipcRenderer.on('messageFromMain', (event, message) => { console.log(`This is the message from the second window sent via main: ${message}`); }); I encou ...

Encountering obstacles when trying to implement mongoose virtuals in a TypeScript environment

I have been exploring how to utilize virtuals in mongoose with typescript. Let's say I have an interface for defining a user. interface User { id: mongoose.ObjectId; name: string; likes: string; } Next, I define a schema for mongoose. // ...

Utilizing numerical values in useParams - A beginner's guide

Trying to access specific data from my json file using an ID, like "http://localhost:3001/pokemons/3", leads to a 404 error. All the data is visible at http://localhost:3001/pokemons. It seems that useParams doesn't want me to use id as a number - q ...

Float32Array should always have a byte length that is a multiple of 4 to avoid any unhandled runtime errors

I am struggling to fetch my custom model in my next.js app. Both the model.json file and the group1-shard1of61 are located in the same folder inside the API directory. I am encountering the following errors: Unhandled Runtime Error RangeError: byte length ...

"Implementing a monorepo with turborepo for seamless deployment on Vercel: A step-by-step

There has been recent news about Turborepo being acquired by Vercel, sparking my interest to dive into it. To start, I initiated a turbo repo project with the following command: pnpx create-turbo Afterwards, I attempted to deploy it on Vercel by referring ...

When utilizing the Turf.nearPoint() function, it is important to consider the type of point being used. The documentation for Turf.nearestPoint() appears to be inaccurate

I have some code that needs to be transcribed from another system, so unfortunately I can't easily share it here. If I could, I would just post the entire project. Recently, I attempted to integrate into our project but encountered error messages. T ...

Using query parameters in Angular to interact with APIs

One scenario involves a child component passing form field data to a parent component after a button press. The challenge arises when needing to pass these fields as query parameters to an API endpoint API GET /valuation/, where approximately 20 optional p ...

Dealing with a multi-part Response body in Angular

When working with Angular, I encountered an issue where the application was not handling multipart response bodies correctly. It seems that the HttpClient in Angular is unable to parse multipart response bodies accurately, as discussed in this GitHub issue ...

Tips for constructing node.js projects using local versions of the dependencies?

Recently, I've been tackling a rather intricate node.js project (find it at https://github.com/edrlab/thorium-reader/) while trying to incorporate local versions of certain dependencies. Surprisingly, I can successfully build and execute the project ...

What is the distinction between revealing environment variables in Next.js using the next.config.js as opposed to utilizing the NEXT_PUBLIC prefix?

As stated in the nextjs documentation, to make my environment variables accessible in the browser, I can simply prepend them with NEXT_PUBLIC in my .env.local file, like this: NEXT_PUBLIC_VAR=7 However, it seems that another approach is available where I ...

Executing a designated assessment in Protractor

Is there a way to run a specific test scenario in my Angular app? I recently added a new feature in Protractor, created the necessary page and steps, but I already have other features implemented. I am wondering if it is possible to solely test the new f ...

The JSX component cannot be 'FieldArray' at this time

I'm working on a next.js project and using the Formik component. However, I encountered a type error that says "'FieldArray' cannot be used as a JSX component." Can anyone help me resolve this issue? Here is the error message: 'FieldAr ...