Issue with resolving node_modules, yet local absolute modules are functioning properly

It's been a real struggle, but my baseUrl is functioning properly and my files are loading correctly. However, when I try to import Chalk from 'chalk, I encounter this error.

i 「atl」: Using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9bdb0b9acbaaabba0b9bd89fae7ffe7fa">[email protected]</a> from typescript
i 「atl」: Using tsconfig.json from C:/Users/adria/Desktop/backup/Business/repositories/xTouch/tsconfig.json
i 「atl」: Checking started in a separate process...
i 「atl」: Time: 719ms
Hash: 13062a08d1faecf0a32b
Version: webpack 4.40.2
Time: 2119ms
Built at: 09/19/2019 12:50:05 AM
 1 asset
Entrypoint main = xtouch.js
[0] ./src/CommandBase.ts 195 bytes {0} [built]
[1] ./src/xtouch.ts 670 bytes {0} [built]
[2] ./src/XTouchCommandManager.ts 648 bytes {0} [built]
[3] ./src/CommandHandler.ts 1.67 KiB {0} [built]
[4] ./src/CommandEcho.ts 512 bytes {0} [built]
[5] ./src/CommandHelp.ts 552 bytes {0} [built]

ERROR in ./src/xtouch.ts
Module not found: Error: Can't resolve 'chalk' in 'C:\Users\adria\Desktop\backup\Business\repositories\xTouch\src'
 @ ./src/xtouch.ts 4:16-32
error Command failed with exit code 2.

I've attempted various solutions, but none seem to work.

// config/webpack.config.ts
const config: Configuration = {
  entry: path.resolve(appSrc, 'xtouch.ts'),
  mode: 'production',
  target: 'node',
  output: {
    path: outDir,
    filename: 'xtouch.js',
  },
  resolve: {
    extensions: ['.ts', '.ts', '.json'],
    modules: ['node_modules', appNodeModules].concat(appSrc || []),
  },
  module: {
    rules: [
      {
        test: /.ts/,
        loader: 'awesome-typescript-loader',
        exclude: /node_modules/,
      },
    ],
  },
};

export default config;

File Structure (for context)

  • config/
    • paths.ts
    • webpack.config.ts
  • node_modules/
  • src/
    • xtouch.ts
    • XTouchCommandManager.ts
    • etc.
  • tsconfig.json
  • package.json

You can even find the public repository here. This situation is really causing me some stress.

Answer №1

It appears that my mistake was having [ '.ts', '.ts' ] instead of [ '.js','.ts'], which caused all node modules to be inaccessible.

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

Error in Typescript index: iterating over properties of a typed object

My scenario involves an interface that extends multiple other interfaces from an external library: interface LabeledProps extends TextProps, ComponentProps { id: string; count: number; ... } In a different section of the codebase, there is an ...

Using TypeScript and encountering Error TS2345 when trying to utilize Promise.all() in a dialog component

I have a TypeScript function that I need help with: private async deleteSelectedLuminaires (): Promise<any[]> { return this.dialogService.open({ viewModel: DeleteLuminaire, model: 'Cancel or Ok', lock: false }) .whenClosed((res ...

Ultimate combo: React, TypeScript, and Vite for seamless imports!

Problem The issue I'm facing is related to my React app built with the command yarn create vite. I tried to switch to using absolute imports instead of "../../.." in my files, but unfortunately it doesn't seem to work in my React + Vi ...

A versatile generic type infused with dynamic typing and optional parameter flexibility

Looking to develop a function that can accept an optional errorCallback parameter. In cases where the consumer of this function does not provide a callback, I aim to default to a preset handler. The key criteria here are strong typing and utilizing the ret ...

Text in Angular vanishes upon reopening

I have a code snippet where I am trying to allow the user to edit and save a paragraph displayed on a side panel of the main page. Although the code works fine, allowing users to update the text and see it reflected in the network upon saving, there seems ...

Angular's observables were unable to be subscribed to in either the constructor or ngOnInit() functions

Currently, I am incorporating an observable concept into my application. In this setup, a service is called by component1 to emit an event that is then subscribed to by component 2. Below is the code snippet for reference: Service Code export class Mes ...

What steps can I take to ensure the reliable functioning of this npm script?

Within my npm package, I have these two straightforward scripts: "prebuild": "rimraf dist types", "build": "tsc", Development dependencies rimraf@^5.0.5 and typescript@^5.3.2 are both installed. However, when I run ...

Is it possible to modify the CSS produced by Bootstrap in an Angular application?

Just starting out with Angular and Bootstrap I have the following displayed in my browser: Browser Code shown through inspect and this is what I have in my code: <ng-template #newSlaVmData let-modal> <div class="modal-header moda ...

Create and release an NPM package using two different design patterns

I have a package that is compiled into a UMD format using Typescript and then transformed into global variables using Webpack. I need to stick with Typescript, so a more flexible UMD pattern is not possible. The goal is to allow applications consuming the ...

Switching from callback to function in TypeScript

Currently, I am utilizing the mongodb driver to establish a connection with mongo: public listUsers(filterSurname?:string):any { if (this.connected) { debug.log(this.db); var results; this.db.collection(' ...

Using Typescript for testing React components: successfully passing an array of objects as props

My current approach involves passing an array of objects to mock component data for testing: const mockPackage = { id: '1232-1234-12321-12321', name: 'Mock Package', price: 8.32, description: 'Mock description', glo ...

Getting the value of the chosen option from one component and passing it to another component in Angular 8

How can I pass the selected option value from the login component to the home component without using local storage? When an option is selected in the login component, I want that value to be displayed in the home component. Below is the code snippet: Lo ...

What is a way to conceal an Angular Material FormGroup on the webpage until the data has been retrieved from the background?

I am working on a simple webpage that includes a form group with multiple controls. In my ngOnInit method, I am sending a get request to fetch data from the server. While waiting for this data to load, I want to hide the form and only display it once the d ...

show the stored value inside the useRef variable

One of my challenges involves a variable const prediction = useRef<any>(null); A button triggers a function that updates the variable's value: function showResult() { classifier.current.classify(capture, (result) => { ...

Calculating the sum of values in a JSON array using a specific parameter in Typescript

A flat JSON array contains repetitive identifier, categoryId, and category: data: [ { "identifier": "data", "categoryId": "1", "category": "Baked goods", "product": "Aunt Hattie's", "price": "375" } ...

Combining observation arrays with RxJS!

Displaying a concise overview of dates is the goal here (a simplified example provided). someArray$: Observable<Date[]> = of( new Date(2019, 11, 1), new Date(2019, 11, 2), new Date(2019, 11, 3)); Following that, a backend call retrieves data in thi ...

Mastering the Use of *ngIf with *ngFor: Best Practices for Proper Implementation

Can someone help me rewrite the combination of *ngIF and *ngFor below? I understand that my issue may be similar to others, but please know that this is different. Everything seems to be working fine. The only problem I'm facing is that the color of ...

Inheriting an Angular 5 class with injected dependencies

I recently defined a new class @Injectable FooService { constructor(private _bar:BarService){ } } Then I decided to extend it in the following way @Injectable ExtFooService extends FooService { constructor(private _bar:BarService){ ...

Angular error: Trying to access the sort property of an undefined value

I am currently working on creating a sorting function and pipe for a table. I found guidance on how to do this by following a tutorial at this link, and here is the plunker example. In the example, the table header should be clickable to trigger the sort() ...

The async/await feature in Typescript fails to trigger updates in the AngularJS view

Currently, I am utilizing Typescript 2.1 (developer version) to transpile async/await to ES5. An issue I have encountered is that when I modify any property linked to the view within my async function, the view does not automatically reflect the updated v ...