No output was generated by Typescript for the file located at '/path/to/file.ts'

My typescript library transpiles smoothly using tsc with the provided configuration:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "lib": [
      "es6",
      "es5",
      "dom",
      "es2017"
    ],
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "listEmittedFiles": true
  },
  "exclude": [
    "./dist",
    "./test",
    "./bin"
  ],
  "include": [
    "./lib"
  ]
}

However, when another project attempts to use this library from a linked npm package and bundle it with webpack and ts-loader, it fails with the following error for all library files:

Error: Typescript emitted no output for /library/path/to/file.ts

Note: Webpack attempts to load the library from the linked destination rather than from node_modules due to its npm link.


The webpack configuration of the project that uses the library is as follows:

module.exports = (entry, dist) => Object.assign({
  entry,
  mode: "production",
  output: {
    filename: "index.js",
    path: dist,
  },
  resolve: {
    extensions: [".js", ".ts"]
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      }
    ]
  },
  stats: 'verbose'
});

The project's tsconfig.json file that uses the library:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "lib": [
      "es6",
      "es5",
      "dom",
      "es2017"
    ],
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": [
    "./dist"
  ],
  "include": [
    "./index.ts"
  ]
}

Below is an example of a library file that fails to emit output:

import {Ctor, Injector} from "./injector";
import {ERROR_CODES, PuzzleError} from "./errors";
import {Route} from "./server";


export interface ApiEvents {}

export interface ApiConfig {
  route: Route;
  subApis?: Array<Ctor<Api>>;
}

interface ApiBase {
}

export function PuzzleApi<T>(config: ApiConfig) {
  return Injector.decorate((constructor: () => void) => {
    console.log(`Registering Api: ${constructor.name}`);

  }, config);
}

export class Api implements ApiBase {
  config: ApiConfig;

  constructor() {
    const config = (this.constructor as any).config as ApiConfig;

    if (!config) {
      throw new PuzzleError(ERROR_CODES.CLASS_IS_NOT_DECORATED, this.constructor.name);
    } else {
      this.config = config;
    }
  }
}

I'm unable to identify why webpack is unable to emit output for that project, as I can transpile the library without any issues. Any assistance would be appreciated.

Answer №1

To troubleshoot this issue, make sure the application is not attempting to import a TypeScript source file directly from the library's lib subdirectory. Instead, try importing the compiled JavaScript file from the dist subdirectory. If you need to compile the library within the application, add it to the "include" list in the application's tsconfig.json file.

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

The application's functionality is interrupted when router.navigate() is called within the .subscribe method

I am having an issue with user navigation on my application. After successfully signing in, users get redirected to the home page (/), but they are unable to navigate by clicking any links on that page. Upon further investigation, I discovered that moving ...

What is the recommended method for deleting sequelize.connectionManager.getConnection according to the Sequelize documentation?

I am currently developing an AWS Lambda function using Typescript that interacts with a database through Sequelize. According to the official Sequelize documentation, the configuration for Sequelize should be as follows: let sequelize = null; async func ...

Encountering Syntax Errors during Angular 6 production build

I encountered an issue with my project. Everything was running smoothly, and even when I executed the command ng build --prod, it compiled successfully and generated the dist folder in my project directory. However, after copying this folder to the htdoc ...

Updates to Angular form control values are not triggering notifications

I am currently working with a basic form control that subscribes to the valueChanges observable. @Component({ selector: 'my-app', template: ` <input [formControl]="control" /> <div>{{ name$ | async | json }}</div ...

Tips for resolving TypeScript issues with Vuex mapGetters

When utilizing mapGetters, TypeScript lacks insight into the getters linked to the Vue component, leading to error messages. For instance: import Vue from 'vue'; import { mapActions, mapGetters } from 'vuex'; export default Vue.extend ...

After using apt to install tsc, I find myself in a dilemma on how to either delete or upgrade it

After realizing I was missing Typescript on my server, I attempted to run the 'tsc' command. However, I received a message suggesting I use 'apt install tsc' instead. Without much thought, I executed the command. Normally, I would insta ...

Is it possible to customize a row with checkboxes in ng2-smart-table when creating a new row?

When adding a new row, I would like a checkbox in the Status column and an input text field in the Image column. You can see an example image here. ...

Choose the Angular 2 option

I am having an issue with the select option in my code. The person's gender property is assigned 'M' for male, but I need to allow users to change it to 'F' for female. Here is the HTML code snippet: <span > <span &g ...

Is there a way to determine if a string is empty, even if it contains hard returns?

I am currently working on a function that checks if a string is empty or not, but it seems to be missing the detection of new lines. export const isStrEmpty = function(text: string): boolean { return !text || text.match(/^ *$/) !== null; }; I attempted ...

Tips for invoking an Android function from an AngularJS directive?

I am facing an issue with my HTML that uses an AngularJS directive. This HTML file is being used in an Android WebView, and I want to be able to call an Android method from this directive (Learn how to call Android method from JS here). Below is the code ...

Ensuring the proper export of global.d.ts in an npm package

I'm looking to release a typescript npm package with embedded types, and my file structure is set up like so dist/ [...see below] src/ global.d.ts index.ts otherfile.ts test/ examples/ To illustrate, the global.d.ts file contains typings ...

Reacting to each change event, Angular dynamically loads new autocomplete options

I am facing an issue with my form where users need to select a company using mat-select-search. Upon selection, an API call is made with the selected company ID to fetch users from that company for the autocomplete feature in recipient fields. The process ...

The custom function is not compatible with any of the available overloads

I'm setting up an event listener that triggers a function to update the state when the event occurs. import React, {useState, useRef, useLayoutEffect} from 'react'; const [width, setWidthIn] = useState<number>(0) const ref = useRef< ...

Issue with React-Router and Webpack: Unable to access a page using a URL parameter

I've seen this question asked multiple times before and despite spending hours searching for a solution, nothing seems to work in my case. Let me give you an overview of my current setup: Packages.json - dependencies "dependencies": { ...

Deactivate the react/jsx-no-bind warning about not using arrow functions in JSX props

When working with TypeScript in *.tsx files, I keep encountering the following error message: warning JSX props should not use arrow functions react/jsx-no-bind What can I do to resolve this issue? I attempted to add configurations in tslint.json js ...

The type 'myInterface' cannot be assigned to the type 'NgIterable<any> | null | undefined' in Angular

I am facing an issue that is causing confusion for me. I have a JSON data and I created an interface for it, but when I try to iterate through it, I encounter an error in my HTML. The structure of the JSON file seems quite complex to me. Thank you for yo ...

TS2688 Error: Type definition file for 'keyv' is missing

The automated code build process failed last night, even though I did not make any changes related to NPM libraries. The error message I received was: ERROR TS2688: Cannot find type definition file for 'keyv'. The file is in the program because: ...

No contains operator found in Material UI Datagrid

While working on a project, I utilized Material UI's datagrid and successfully implemented filters such as contains and isEmpty. However, I am struggling to find information on how to create a notContains filter. Does Material UI natively support this ...

Tips for dynamically loading a child component and passing data from the child component to the parent component

In my current setup, I have organized the components in such a way that a component named landing-home.component loads another component called client-registration-form.component using ViewContainerRef within an <ng-template>, and this rendering occu ...

The utilization of the rest parameter in combination with generics

I encountered an issue with my iteration. The error message "Operator '+=' cannot be applied to types 'number' and 'T'" is showing up. I am puzzled as to why this is happening. let a: number = 1, b: number = 2, c: number ...