Unresolved dependencies causing a rollup error

When I try to use import file from 'file.json' in a Vue component and run npm run build to bundle it with Rollup, I encounter an issue.

An error is thrown during the process, preventing the file from being bundled as expected.

https://i.sstatic.net/LWThA.png

This is the content of my `rollup.config.js`:

import vue from 'rollup-plugin-vue'; 
import buble from 'rollup-plugin-buble';
import resolve from 'rollup-plugin-node-resolve'
import json from 'rollup-plugin-json'

export default {
input: 'src/plugin.js',
output: {
    name: 'NaijaStatesLgas',
    exports: 'named',
},
plugins: [
    json(),
    resolve({
        jsnext: true,
        main: true,
        browser: true,
        extensions: [".js", ".json"],
        preferBuiltins: false,
    }),
    vue({
        compileTemplate: true, 
function
        }),
        buble(),
    ],
};

I would appreciate any guidance on how to resolve this issue. Thank you!

Answer №1

To solve the issue, I made a simple adjustment from import file from 'file.json' to import file from './file.json'. This change enabled the file to be recognized as a local module.

Answer №2

Expanding on the explanation provided by Justin...

As outlined in the referenced documentation available at Warning: "Treating [module] as external dependency"

"By default, Rollup only resolves relative module IDs. This means that when using an import statement like this ... import moment from 'moment'; ... it will not include 'moment' in the bundle but treat it as an external dependency required during runtime."

This clarifies why utilizing Justin's approach with... import moment from './moment'; ... is effective.

The documentation also suggests incorporating @rollup/plugin-node-resolve to handle dependencies efficiently.

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 Server-Side Rendered page is experiencing inconsistencies in rendering

I am currently working on a straightforward NextJS project with just one page. The application is configured to utilize redux, next-redux-wrapper, and redux thunk. It is important that the page always undergo server-side rendering. Here is an example of h ...

Adding Rotation to a group in Three.js using a pivot point

I'm currently in the process of constructing a Rubik's Cube using Three.js. My method involves grouping all the small cubes that need to be rotated together and then performing the rotation on the group as a whole. To determine the pivot point fo ...

Converting Model Object into JSON Format

I am attempting to convert a statistical model object into a JSON file for exchange with an API. However, the challenge lies in the fact that JSONs cannot directly handle raw model objects due to the presence of class types within the objects that are not ...

Tips for displaying HTML content from a JSON web template

Currently, I am working with a JSON web template that consists of nested elements. My goal is to render HTML based on the content of this JSON web template. I attempted using ngx-schema-form, however my JSON does not contain properties variables. I also t ...

Reverting to the original order in jQuery DataTables after dropping a row

Recently, I've been attempting to utilize jQuery DataTables in conjunction with the Row Ordering plugin. At first, everything seemed to be functioning properly until a javascript error popped up indicating an unrecognized expression. After researching ...

Tap on the div nested within another div

Here is the scenario I am dealing with: <div id="main"> <div id="a"></div> <div id="b"></div> </div> On my website, element B is positioned below element A. How can I attach a click event only to those A elements t ...

Tips for incorporating JSON data into an HTML table

https://i.sstatic.net/WEdge.jpgIn an attempt to showcase JSON data in an HTML table, I want the schoolClassName value to be displayed as a header (th) and the first names of students belonging to that specific schoolClass to appear in a column beneath the ...

What is the best way to create a tree structure that can hold data from multiple sources?

I have a variety of Models within my application: ModelA: fields: [id, name], hasMany: ModelB ModelB: fields: [id, name, attr], hasMany: ModelC ModelC: fields: [id, name, attr] To efficiently manage this nested data, I utilize a data store in conjuncti ...

It appears that Nodemon has stopped functioning correctly. To use Nodemon, simply input the following command: nodemon [nodemon options]

nodemon has always been reliable for me. I used to run nodemon server and it would automatically watch for updates and restart the server file. However, lately when I try to do this on my Windows cmd, I get the following message: Usage: nodemon [nodemon o ...

Tips for emphasizing a specific field in search results with Solr

I am looking to add a highlighting feature to my search application using Solr. After making the necessary changes in the config file for highlighting, I ran the URL with hl=true&hl.fl=somefield and received the <highlighting> tags. Now, I want t ...

Import data from a distant file into a node Buffer within the web browser

Currently, I am utilizing browserify to utilize this particular package within the browser. Specifically, I have developed a phonegap application that retrieves .fsc files from the server. The code snippet looks like this: var reader = new FileReader( ...

Deviations in Scriptaculous Callbacks during Movement Effects

I am looking to create a dynamic menu item that moves out 5px on mouseover and returns to its original position using Scriptaculous. I have implemented the afterFinish callback to ensure that the bump-out effect is completed before the item moves back in. ...

Looking to break down the string in Java and then parse it with JSON

Hey there, I've got a lengthy string containing three parameters separated by "|" symbols. How do I split it in Java and then JSON.parse one of the parameters? Your assistance is greatly appreciated. ...

What is the best way to find the maximum and minimum values within a JSON object that is populated from user inputs using only JavaScript?

Here is a simple form that stores data at the following link: https://jsfiddle.net/andresmcio/vLp84acv/ var _newStudent = { "code": code, "names": names, "grade": grades, }; I'm struggling to retrieve the highest and lowe ...

Refreshing the page allows Socket.io to establish multiple connections

I've been working on setting up a chatroom, but I've noticed that each time the page refreshes, more connections are being established. It's interesting because initially only one connection is created when I visit the chat room page. Howeve ...

Using jQuery AJAX, the value of a server-side control (textbox) can be easily set

After working with the code below, I noticed that I can only set the value received from an ajax call if I am using HTML controls like buttons and text boxes. If I try to use asp server controls such as a button, the ajax call does not return any output, e ...

Global Day "Sequence" Initiates Subtraction Instead of Preserving Its Authentic Structure

While using Python's Selenium, I am facing a challenge when trying to "inject" an international date string in the specified format into a web page. Unfortunately, instead of getting the expected string, I am getting a result that seems like subtracti ...

How can I include inline CSS directly within a string instead of using an object?

Is there a way to write inline CSS in a string format instead of an object format? I attempted the following, but it did not work as expected: <div style={"color:red;font-weight:bold"}> Hello there </div> What is my reason for want ...

Problem with Bcryptjs Async Implementation

I have implemented a function in my node server using bcryptjs to hash and compare passwords. Here is the code snippet: this.comparePasswords = function(password1, password2, callback) { bcrypt.compare(password1, password2, function(error, result) { ...

How is the height or width of the Bootstrap modal determined?

I'm having trouble utilizing Jschr's modified Bootstrap-Modal for different modal sizes. I can't seem to understand why some modals appear taller, wider, or have other specific dimensions. For more information, refer to the documentation: ...