making changes to the JS node dependency package results in a syntax error during compilation process, particularly within the npm/Vue.js environment

After creating a Js library and encountering stability issues and a few bugs that need fixing, the dilemma of developing a library arises when HMR does not work with dependencies. Here's a possible solution:

  • To start, create a new Vue project using the command: vue create fooproject and navigate into that directory.
  • Add a local javascript module as a dependency.
    • You can download the library to your ~/tmp directory. Then add it using:
      npm install --save ~/tmp/vue-extensions # or specify the directory where your library is located
      .
  • Your node_modules should now contain a symlink to that directory.
  • Run npm run serve to compile the Vue project and start the development web server. Remember to keep the terminal open.
  • Make changes to the code in the local vue-extensions library (such as adding a whitespace) and save it.
  • Initially, nothing will happen as the lib was not compiled with the change. Imports are searching in the dist/ directory, which is normal according to my knowledge.
  • Go to the vue-extensions directory and run npm run build. This should successfully build the library.
  • At this point, the first terminal should show a change: Webpack should detect the code change and trigger HMR. However, it may break initially as webpack might not find vue-extensionpoints.common.js temporarily (before recreating it):
Module build failed (from ./node_modules/eslint-loader/index.js):
Error: ENOENT: no such file or directory, open '/home/christian/vue-extensionpoints/dist/vue-extensionpoints.common.js'

 @ ./src/main.js 7:0-50 10:8-23
 @ multi (webpack)-dev-server/client?http://192.168.4.3:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

To resolve this, simply restart the build: npm run serve.

Unfortunately, more problems arise at this point with multiple errors:

error: Unexpected newline between function and ( of function call (no-unexpected-multiline) at ../../Projekte/vue-extensionpoints/dist/vue-extensionpoints.common.js:88:10:
  86 | /******/ })
  87 | /************************************************************************/
> 88 | /******/ ({
     |          ^
  89 | 
  90 | /***/ "06cf":
  91 | /***/ (function(module, exports, __webpack_require__) {


error: 'exports' is defined but never used (no-unused-vars) at ../../Projekte/vue-extensionpoints/dist/vue-extensionpoints.common.js:135:25:
  133 | 
  134 | /***/ "1d80":
> 135 | /***/ (function(module, exports) {
      |                         ^
  136 | 
  137 | // `RequireObjectCoercible` abstract operation
  138 | // https://tc39.github.io/ecma262/#sec-requireobjectcoercible


error: 'exports' is defined but never used (no-unused-vars) at ../../Projekte/vue-extensionpoints/dist/vue-extensionpoints.common.js:370:25:
  368 | 
  369 | /***/ "5135":
> 370 | /***/ (function(module, exports) {
      |                         ^
  371 | 
  372 | var hasOwnProperty = {}.hasOwnProperty;
  373 | 


error: 'exports' is defined but never used (no-unused-vars) at ../../Projekte/vue-extensionpoints/dist/vue-extensionpoints.common.js:417:25:
  415 | 
  416 | /***/ "5c6c":
> 417 | /***/ (function(module, exports) {
      |                         ^
  418 | 
  419 | module.exports = function (bitmap, value) {
  420 |   return {


error: 'exports' is defined but never used (no-unused-vars) at ../../Projekte/vue-extensionpoints/dist/vue-extensionpoints.common.js:603:25:

[...and so on...]

To overcome these errors, break with Ctrl+C and run npm run serve again, and it should work.

Clearing the npm cache with npm cache clear [--force] may not resolve the issue.

It's frustrating to have to rebuild the library and stop and restart the main server twice to see changes. Surely, there must be a simpler way to develop libraries, right?

Thank you in advance.

Answer №1

Can you believe it? Once again, after hours of frustration, I managed to solve the problem on my own shortly after posting on Stackoverflow...

All it took was deleting the /dist/ folder in the lib, and voila, the issue was resolved.

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

Can you explain the significance of the error message stating "XMLHttpRequest.timeout cannot be set for synchronous http(s) requests made from the window context"?

I'm experiencing some timeouts with a synchronous XML HTTP request in Safari on my Mac. In an attempt to fix this issue, I added a timeout setting like this: req.open(this.method, fullURL, this.isAsync); req.setRequestHeader('Content-Typ ...

GlobalsService is encountering an issue resolving all parameters: (?)

I am currently working on implementing a service to store globally used information. Initially, the stored data will only include details of the current user. import {Injectable} from '@angular/core'; import {UserService} from "../user/user.serv ...

Having trouble establishing a connection between MongoDB and a Node.js Express server on my local machine

While attempting to establish a connection between mongoDB and nodejs express using the post method, I added a logger that should display a message confirming that the database is connected once nodejs listens to mongoDB. However, I encountered an issue wh ...

How can data be displayed in AngularJS/Json without using ng-repeat?

It seems like I am required to use ng-repeat in order to display the data, but I would prefer to avoid using it. angular: App.controller('aboutLongCtrl', function ($scope, $http) { $http.get('test_data/ar_org.json') .then(func ...

Vue - Struggling to send props to dynamically imported Web Components

Long time no see, old friend. I am navigating to a Vue file that is asynchronously imported (via import) upon routing. The template for this file is shown below, mainly serving as a way to load in a heavier web component and create separation from that co ...

Receive a warning in the Heroku log stating "(node) sys is outdated. Util should be used instead" while the script is executed

I recently deployed a Node script on Heroku to be executed by a scheduler. However, upon running the script, I noticed a warning message in the logs. Dec 07 11:01:10 xxx heroku/scheduler.3255 Starting process with command `node bin/script` Dec 07 11:01:1 ...

Get Onsen UI 2 up and running without the need for Angular

Is it possible to install Onsen UI 2 without Angular? I have tried following various guides from , but when attempting the JavaScript method (> npm install onsenui) I consistently encounter a ReferenceError: angular is not defined. How can I properly in ...

Obtaining a complex object from a Checkbox set in AngularJS through the use of ngModel

Hey there! I've been searching on Stack Overflow regarding this topic, but I haven't found a solution that matches exactly what I need. If you want to take a look at the code, here is a JSFiddle link for reference: http://jsfiddle.net/gsLXf/1/ ...

TinyMCE: Tips for adding and highlighting text in your content!

Is there a way to insert, or even replace the current selection with some content and then have it automatically selected? Take for instance this text: Hello nice world! The user has selected nice. After clicking a button, this code is executed: editor. ...

jQuery Show/Hide Not Working Properly

I'm attempting to showcase one Tweet at a time and have it rotate through different tweets. I'm facing an issue where it works correctly on one type of page, but not on the other. Could this be due to a CSS precedence rule overriding the function ...

Having trouble importing zone.js in Angular 14 and Jest 28

I am currently in the process of updating to Angular 14. Everything is going smoothly except for setting up jest. Since I have Angular 14 libraries included in my build, I need to utilize jest-ESM support. Below is my configuration: package.json { &qu ...

Ways to stop Bootstrap collapse from displaying depending on a certain condition in bs5 framework

I've been struggling to figure out how to prevent a collapsible panel from opening or showing if a specific value is null. Despite multiple attempts, I haven't had any success. HTML <a href="#" data-bs-toggle="collapse" da ...

To iterate through a multi-dimensional array

I am facing an issue with fetching data within an array in the code below var str = "Service1|USER_ID, Service1|PASSWORD" var str_array = str.split(','); console.log(str_array) for(var i = 0; i < str_array.length; i++) { str_array[i] = st ...

Passing a node.js variable to an ejs template through a post request

In my nodejs application, I utilize Express JS to handle post requests. Within the INDEX.JS FILE, the following code snippet is present: this.app.post('/profile', (req, res, next) => { let password = req.bo ...

Return to the previous URL after executing window.open in the callback

I need help redirecting the callback URL back to the parent window that initially called window.open. Right now, the callback URL opens inside the child window created by the parent. Here's the scenario: The Parent Window opens a child window for aut ...

JavaScript tip: Finding the total sum of strings with time format (e.g. 00:00:00)

I have an array that contains time values: // hours, minutes, seconds let arr = ["00:00:30", "00:20:00", "01:00:10", "05:10:15"] Is there a way to calculate the total sum of these elements? output: "06:30:55" ...

The Angular 2 project, built with the CLI tool, has been transformed into an npm

We have a project in the works that involves creating a large application using angular 2. This project consists of one main parent angular 2 application and three separate sub-child applications that are unrelated to each other. Each of these sub-child ...

Transform asynchronous calls into synchronous calls

During my time building web applications in PHP, I was accustomed to handling tasks synchronously. Currently, my focus is on constructing a web scraper. The process involves: Obtaining a list of proxies Verifying the status of the proxies Scraping web c ...

Retrieve information from a database in real-time using Ajax without needing to set a refresh interval

Currently, I have been working on jquery/ajax requests and have managed to create an ajax request that retrieves data from a database. However, the issue at hand is that I am continuously utilizing window.setInterval() to refresh this function every x seco ...

What is the best way to retrieve the results from the event handler triggered by window.external.Notify("someText") in order to send them back to JavaScript?

Using window.external.Notify("someText") in my Windows Phone 8 HTML5 Application function func() { window.external.Notify("clearTextBox"); } An event handler for ScriptNotify has been implemented private void BrowserScriptNotify(object sender, Not ...