Error in Nuxt npm js package [Stack frames not found]

I've been attempting to incorporate the format-unicorn npm package into my Nuxt application. However, upon importing it into my Vue page, I encountered the following errors:

Client: Missing stack frames
Server: [Vue warn]: Error in render: "TypeError: this.currencyFormat.formatUnicorn is not a function"

Initial Strategy

According to the plugins documentation, the following approach should work:

Another way to use package without installing the module is by directly importing package in the <script> tag.

// Product.vue
<template>
  <div class="product">
    <p>Price: {{ localizedPrice }}</p>
  </div>
</template>

<script>
require('format-unicorn')

export default {
  data() {
    return {
      currencyFormat: '{c}{p}',
      currency: '$',
      price: 12.99
    }
  },
  computed: {
    localizedPrice: {
      get() {
        return this.currencyFormat.formatUnicorn({c: this.currency, p:this.price})
      }
    }
  }
}
</script>

However, this approach resulted in an error: Missing stack frames (with no further useful information).

Additionally, in the node console:

[Vue warn]: Error in render: "TypeError: this.currencyFormat.formatUnicorn is not a function"

Interestingly, the page loads without errors if I navigate there using Nuxtlink. But upon refreshing, the error reappears.

Using Plugins Approach

Even after creating the format-unicorn.js file within the plugins directory, I faced the same error:

//// plugins/format-unicorn.js
require('format-unicorn');
//// nuxt.config.js
// ...
plugins: [
    '~/plugins/format-unicorn.js'
//  applying mode: 'client' or 'server' doesn't help as well
  ],
// ...

Simple Plugins Solution

To test its functionality, I decided to paste code from the package repository directly into the plugin (and surprisingly, it worked):

//// plugins/format-unicorn.js
String.prototype.formatUnicorn = function () {
  let str = this.toString()

  if (arguments.length) {
    const type = typeof arguments[0]
    const args = type === 'string' || type === 'number' ? Array.prototype.slice.call(arguments) : arguments[0]

    for (const arg in args) str = str.replace(new RegExp(`\\{${arg}\\}`, 'gi'), args[arg])
  }

  return str
}
//// nuxt.config.js
// ...
plugins: [
    '~/plugins/format-unicorn.js'
  ],
// ...

Summary

It's clear that the naive approach is not sufficient for my needs, especially considering future integration of third-party packages into my app. My main question remains: What am I missing or doing wrong in trying to extend a prototype from a Nuxt plugin?

Answer №1

After encountering the "Missing stack frames" error message in my nuxt project, I successfully resolved it by halting the process with Control-C and then initiating it again using the command npm run dev.

Answer №2

Encountered the "Missing stack frames" error in my nuxt project when using node 12, but was able to resolve it by following these steps:

  1. Stop the process with Control+C

  2. If needed, change to the specific node version you require.

nvm use 12
  1. Run this command:
yarn cache clean
  1. To reinstall node modules, execute the following:
rm -rf node_modules/
yarn install --ignore-engines
  1. Finally, run:
yarn dev

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

Update various components within a container

I have incorporated a function that automatically loads and refreshes content within a div every 10 seconds. Here is the script: $(function () { var timer, updateContent; function resetTimer() { if (timer) { window.clearTimeout(timer); ...

Using the Ajax method from a separate class in TypeScript: A step-by-step guide

Recently, I started learning about typescript and ajax. One of the challenges I encountered was while creating a method in typescript for making ajax calls that can be used across classes: myFunc(value: string): JQueryPromise<any> { var dfd = $. ...

Encountering an Invariant Violation: React does not allow objects to be used as children

I can't figure out why my code isn't working. Every time I run it, I get the error message: Invariant Violation: Objects are not valid as a React child (found: object with keys {_40, _65, _55, _72}). If you meant to render a collection of chil ...

React-native experiencing complications with node version requirement

Trying to set up react-native init on my mac, I encountered the following issue: Node v0.10.30 is currently installed, however React Native requires version >=4. Please make sure you have a supported version of Node installed. When I attempted to upgra ...

Sending HTML input data to jQuery form field

Is there a way to pass HTML text input values into a Stripe form? Here is an example of what I currently have: <input type="text" name="trip" id="trip" value=""> JS: (part of the form) .append(jQuery('<input>', { 'nam ...

Personalized modify and remove elements on a row of the DataGrid material-ui version 5 component when hovered over

In my React Js app, I am utilizing Material UI components or MUI v5 as the UI library for my project. Within the DataGrid/DataGridPro component, I am implementing a custom edit and delete row feature. The requirement is to display edit and delete icons w ...

What is the best way to set conditions for document side script?

I'm struggling to disable the horizontal scroll when the viewport width is 480px or less. The script that controls the scroll behavior on my website looks like this: <script> $(function () { $("#wrapper").wrapInner("< ...

How to Use Django to Load a Text File into an HTML File with the Help of

I came across an interesting code example on a website called w3schools.com that I would like to incorporate into my Django project. The code utilizes the jquery load() function to load a text file into an HTML file. Here is a snippet of the code: <!DOC ...

Creating a custom Angular HTTP interceptor to handle authentication headers

Necessity arises for me to insert a token into the 'Authorization' header with every HTTP request. Thus, I created and implemented an HttpInterceptor: @Injectable() export class TokenInterceptor implements HttpInterceptor { constructor(public ...

What is the best way to reduce the width of the preformatted tag?

Is there a way to adjust the width of the pre tag in order to avoid affecting the q-card when resizing the browser window? I am trying to create a q-card that can display code similar to what you see in ChatGPT. However, the q-card's size is not respo ...

Elements within HTML are not recognized by external JavaScript files

I've come across a perplexing issue while coding in JavaScript, and despite searching online, I can't seem to find a solution. Basically, I have created an HTML document and linked it to an external JS file. However, when I try to reference an e ...

Having trouble with jqGrid data format?

Having some trouble with jqGrid and displaying data in a treeview format. The issue is that the 6th item (cid=6) is not appearing in the grid. Additionally, it seems like the 4th item may have subitems, but expanding that branch reveals nothing. I cannot f ...

The datetimepicker is not functioning properly

I'm experiencing an issue with the datetimepicker where it doesn't display a calendar when I click the icon. Interestingly, the Chrome browser isn't showing any errors in the development console. <script src="Scripts/jquery-2.1.1.min.js ...

Obtain Relative URL with the help of Selenium using the PhantomJS driver

Utilizing Selenium along with the Phantom JS driver, I am attempting to load an HTML page and extract all of the HREF links from it. The issue arises when PhantomJS provides absolute URLs after resolving them entirely. My specific requirement is to extrac ...

The jQuery click event for sending data is not functioning properly, as it only updates the existing

I am currently working on implementing a click send function for my emoticon feature but I'm facing some issues with it. You can view the interactive demo I created on JSFiddle. The demo features four text areas and emoticons. When you click on an em ...

Adding points to vertices on mesh geometry based on their distance

My scene includes a THREE.Geometry with more than 5,000 vertices. I am looking to add THREE.Points to the scene for only 3 specific vertices of the mesh within the geometry. My goal is to achieve a similar outcome as shown in this example: https://i.sstat ...

Execute a series of Promises (or Deferreds) consecutively and have the flexibility to pause or stop at any point

Having an issue here. Need to make numerous consecutive http calls and the ability to stop the process at any point in time. The current solution I have involves jQuery and Deferreds, but it lacks proper interruption handling (still haven't transition ...

How can I temporarily change an image when clicking on it using JavaScript?

I am working on an image section where I want to change the image for a few seconds when clicked and then revert back to the original image. Here is the code I have tried: <img src="contacticons.jpg" usemap="#image-map" id="imgName"> <a onclick ...

The npm installation for react-icons is failing to add the package

I am new to React and I'm attempting to download react-icons. However, I encountered an error that is different from what I have seen before. Can anyone offer assistance? (base) Jana-MacBook-Air:react_project jb$ npm install react-icons --save Respo ...

I am experiencing issues with my asynchronous request in Express

I'm currently in the process of transitioning my requests to async calls to prevent them from blocking. app.js app.use(function(err, req, res, next) { res.locals.message = err.message; res.locals.error = req.app.get("env") === "development" ? er ...