Unable to load connected modules from npm/yarn link within the WSL environment

Trying to import a local dependency into my project is proving to be quite challenging.

The situation at hand involves a project named 'test_project' and another one called 'test_module'. Linking test module to the global node_modules folder using either npm link or yarn link has been attempted. Subsequently, test_module is linked in test_project. Upon importing test_module into the index.js file and attempting a yarn/npm start, the following error arises:

Failed to compile.

./src/index.js
Cannot find file: 'index.js' does not match the corresponding name on disk: '/mnt/c/users/<my_username>/Projects/test_module/Users'.

There seems to be an issue where '/Users' is being erroneously appended to the end of the path. I've reset my environment twice but the problem persists. Could this possibly be related to WSL? Is there a misconfiguration that I'm overlooking?

UPDATE: The 'test_project' was created with create-react-app without any alterations. Just adding some context about my environment setup.

UPDATE2: Testing this in Window's CMD produced the desired outcome. It appears that the issue is connected to a combination of factors involving WSL, my node installation, and potentially other unknown variables :/

Appreciate any help

Answer №1

I have successfully found a solution to the problem at hand. By editing your WSL configuration and setting the root to '/', I was able to eliminate any relative path issues that may have been causing the problem. This allows the path to properly step back without '/mnt/' in the way. Although I can't offer concrete evidence for my theory, it seems to be effective :D

The fix is quite simple.

sudo vim /etc/wsl.conf

Add the following field to make the file look like this:

[automount]

root = /
options = "metadata"

(I included the options field to address permission problems)

After making these changes, fully logout/signout, log back in, unlink the module, delete the node_modules folder, run npm install, and then re-link. Everything should function correctly at that point.

Cheers!

Answer №2

This problem had me frustrated for a considerable amount of time, but I managed to find a solution while working on my current project. (Remounting the WSL root didn't resolve the issue for me, unfortunately.) The symptoms I experienced were slightly different from those mentioned in the original question, but I hope that sharing what I discovered may offer some valuable insight.

In my case, the issue stemmed from a combination of factors and only occurred when attempting to run react-scripts start for a specific project. What puzzled me was that I had another project within WSL with an almost identical setup that ran smoothly without any issues.

After extensive investigation, I identified the root cause as the case-sensitive-paths-webpack-plugin used internally by react-scripts. By strategically inserting several console.log() statements in the fileExistsWithCase method, I was able to pinpoint where the problem lied.

The function is responsible for checking whether a file or directory on disk matches the given string (filepath) in terms of casing. To achieve this, it recursively traverses each directory in the path. Unfortunately, there appears to be an issue with error logging. When an error propagates through the recursion loops, it mistakenly appends the name of the problematic folder as if it were the original filename (I reported this as an issue in the create-react-app repository).

For instance, the error message from the initial question stated:

Cannot find file: 'index.js' does not match the corresponding name on disk: '/mnt/c/users/<my_username>/Projects/test_module/Users'.

In this scenario, after several recursions, the library listed all contents in /mnt/c, and upon noticing that the directory users did not exist but Users did, the error surfaced incorrectly citing

/mnt/c/users/<my_username>/Projects/test_module/Users
.

During file or directory checks, the library first investigates its cache and preloads the cache with the current working directory for reference. This discrepancy explained why one project worked while the other failed. The successful project utilized npm, with its node_modules structured as $PWD/node_modules/foo, which halted recursive searches once reaching $PWD. Conversely, the failing project employed pnpm, hoisting dependencies to a higher level. In my scenario, validation errors occurred when verifying the directory /mnt/c/Users/[username]/wslhome, erroneously perceived as WSLHome on disk.

I resorted to renaming WSLHome to wslhome, enabling functionality in my project. Regrettably, renaming /mnt/c/Users posed challenges since Windows created it.

Essentially, the issue seemed linked to how the package's dependencies' absolute paths were defined and whether their casings coincided with Node's path interpretations.

UPDATE: Recently, upon revisiting the project, I encountered failures again, this time complaining about inaccurate casing in the "Users" directory. To rectify this, I stumbled upon an article regarding enhancing case sensitivity options when accessing Windows directories. After incorporating case=dir into my wsl.conf preferences and restarting the subsystem, the error vanished. However, due to its erratic nature, I cannot definitively confirm it as the resolution.

An additional potentially relevant observation involves inconsistencies seen when executing readlink -f on a dependency directory. Sometimes, outcomes reflect accurate casings, while other times they do not. For example, currently, readlink -f ~/dev inaccurately returns a subdirectory of /mnt/c/users, whereas readlink -f . correctly illustrates a subdirectory of /mnt/c/Users when within the ~/dev directory.

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

What is the best method to choose a random color for the background when a button is pressed?

Does anyone know how to create a button that changes the background color of a webpage each time it is clicked? I've been having trouble with the javascript function in my code. I've tried multiple solutions but nothing seems to work. Could someo ...

The proper method for updating data on a backend API using Axios and Vue

I am working on a Vue application that includes several form fields. I want to ensure that any changes made by the user are saved in real-time to a backend database using a REST API with Axios, without requiring the user to click a save button. I have two ...

Attempting to instruct my chrome extension to execute a click action on a specific element found within the webpage

I am currently working on developing a unique chrome extension that has the capability to download mp3s specifically from hiphopdx. I have discovered a potential solution, where once the play button on the website is clicked, it becomes possible to extract ...

npm encountered a premature closure

I recently purchased and started using a ReactJS template which you can check out here My goal is to install all the dependencies by running npm install in the root directory of the template (React-App) However, I encountered an ERROR message like this: ...

Icons in React are used to visually represent various actions

I am facing an issue with the React icons I imported on my personal website. They are not displaying at all. Despite reinstalling React Icons multiple times, with and without --save, the problem persists. I have thoroughly checked both the node_modules dir ...

Pass a variety of data points to PHP using Ajax requests

I am facing a challenge with passing multiple parameters during Ajax calls. The code works perfectly when I only pass one parameter. Here is the code snippet for the Ajax call: $.ajax({ type: "POST", url: "dataCartas.php", ...

Issue encountered while attempting to compress tailwindcss

I attempted to reduce the size of my tailwindCSS by creating a script in my package.json: "tw:prod":"NODE_ENV=production npx tailwindcss-cli@latest build ./src/css/tailwind.css -o ./public/css/tailwind.css", However, I encountered the ...

What causes the error message 'avoid pushing route with duplicate key' when using NavigationStateUtils in React Native?

Within my React Native + Redux project, I have set up a reducer for navigation utilizing NavigationStateUtils: import { PUSH_ROUTE, POP_ROUTE } from '../Constants/ActionTypes' import { NavigationExperimental } from 'react-native' impo ...

What is the process for passing a .js file into .ejs using Node.js?

I am facing an issue with loading the popmotion library into my main page, which is an .ejs file being passed to Node/Express. The code in my file popmotion.js is not running, and I want to control DOM elements mentioned in the ejs file through this file. ...

New React Component Successfully Imported but Fails to Render

I've encountered issues with the code I'm currently working on. Dependencies: React, Redux, Eslinter, PropTypes, BreadCrumb Within a view page, I am importing components from other files. The current structure is as follows: import Component ...

Leveraging Parameters in Ajax with jQuery and JavaScript

I've been exploring jQuery and trying to update a specific TD element with innerHTML. However, I'm stuck on how to capture the value of a parameter. In this scenario, my goal is to grab the user-id "1234" in order to update the TD identified as ...

A guide on utilizing webpack devServer proxy within a create react app

Currently, I am in the process of developing a new application with create-react-app and I am looking to incorporate some proxies into my code. In the past, I utilized webpack's devServer for this purpose. module.exports = { ... devServer: { ...

How can we effectively manage error responses and retry a failed call in NodeJS without getting tangled in callback hell?

I am in search of an effective approach to handle the given situation. I am curious if employing promises would be a helpful solution? Situation Overview: When a call retrieves a callback, and this callback receives an error object as a parameter. My obj ...

What are the steps for installing the most recent SNAPSHOT version using npm?

We maintain a private nexus repository where we publish all npm modules. Two of our modules, Module A and Module B, have a dependency where Module B relies on Module A. I am encountering an issue with installing the latest SNAPSHOT version. For instance: M ...

A guide on incorporating Google authentication into Vue.js with the use of TypeScript and the component-based syntax

Currently, I am in the process of integrating Google authentication into my Vue.js front end. The project was initialized using CLI with TypeScript and component style syntax enabled, alongside other configurations. Additionally, there is a backend web ser ...

Issues with the count up functionality in jQuery

I'm currently working on a project involving countups. My aim is to have multiple countups displayed on a single page. While having one countup using interval() function poses no issues, I encounter trouble when trying to display two or more countups ...

Can a synchronous loop be executed using Promises in any way?

I have a basic loop with a function that returns a Promise. Here's what it looks like: for (let i = 0; i < categories.length; i++) { parseCategory(categories[i]).then(function() { // now move on to the next category }) } Is there ...

Leveraging underscore.js for null verification

let name = "someName"; if(name !== null) { // perform some action } Currently, I am utilizing http://underscorejs.org/#isNull. How can I achieve the same functionality using underscore.js? Is there any noticeable performance enhance ...

Runtime not able to identify new modifications post migration from Angular 2 to Angular 6

I successfully upgraded my Angular 2 project with DotNetCore to Angular 6 by executing the following command: npm install -g npm-check-updates ncu -u After completing the migration process, I found that while I can still run my previously developed proje ...

Unable to deploy a node.js package via a jenkins job

I'm looking to set up a Jenkins job that will publish a package to npmjs.com. The source code for the package is located in a GitHub repository. While I am able to successfully publish the package from my personal computer by running 'npm publis ...