Utilizing ES6 modules in an Adobe XD extension: A comprehensive guide

Is it possible to utilize ES6 imports within XD plugins?

When attempting to use import Vue from 'vue', the build task is successful, but XD throws an error in the developer console during plugin loading:

Plugin Error: Error loading plugin <settings>/develop/my_plugin
Plugin TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
    at Module.<anonymous> (<settings>/develop/my_plugin/main.js:14367:16)
    ...

I initially started with the Hello Vue Dialog example found here, which was then converted to a Panel. The same error persists even when using the dialog example instead. There were no alterations made to the package.json and webpack.config.js files, so the libraryTarget remains as commonjs2. Do I require an additional plugin to resolve ES6 module imports?

In another thread, Adobe XD's support for ES6 Imports and Exports is not explicitly mentioned: Can you use ES2015+ features (ES6) in Adobe XD plugins?

Since my code base heavily relies on ES6 modules, I would like to seamlessly integrate it into the plugin without having to replace every import statement with require.

If necessary, I can provide a minimal example.

Thank you for your assistance.

Best regards, Daniel

Answer №1

Fixing this issue is quite simple, as long as you are familiar with writing export statements.

In the main.js file, just swap out

module.exports = {
    panels: {
        mainPanel: { show, hide, update }
      }
};

with

export const panels = {
    mainPanel: { show, hide, update }
}

as suggested by @kerrishotts on Twitter: https://twitter.com/kerrishotts/status/1249832641857114114

After making this change, you'll be able to utilize import and export statements throughout your project.

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

I am encountering TypeError issues while attempting to mock/test Vuex store modules

I'm currently in the process of learning how to effectively test components and JavaScript code, but I have hit a roadblock with Vuex modules. Below is the code snippet for the test: import { shallowMount } from '@vue/test-utils' import Wor ...

The collapsible toggle feature is currently not working as intended

I have tried looking for solutions but have not been successful. My apologies for asking what may seem like a simple question. The toggle button is not expanding to show the menu items when clicked. It works fine on the "home" page but not on the linked pa ...

Every time I try to install create-react-app, I keep encountering a frustrating 'network Socket timeout' error

$ npx create-react-app amazon-clone npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. Creating a new React app in D:\js\faceboom. npm WARN config global `--global`, `--local` are deprecated. ...

Automatically submitting a form in the absence of the user from the page

Is it possible to automatically submit a form when the user exits the page? Here's the code snippet: <form class="carform" method="get"> <input type="hidden" name="number_plate" value="{{ car.number_plate }}"> </form> I want the ...

Issue with Access-Control-Allow-Origin header encountered while interacting with Reddit's JSON API

Currently working on a React app that fetches data from the reddit JSON api. During development, I used the cors-anywhere demo assuming that CORS errors wouldn't appear in production. After researching CORS errors, I learned that they occur because t ...

Viewing a ViewChild in Angular 8 results in receiving an undefined value

Struggling to access the childView instance as it keeps showing that the childView is undefined. Below is the code snippet for childViews: @ViewChild(CreateQuestionnaireComponent,{ read: true, static: false }) private childQuestionnaireDialog:CreateQues ...

How to access a value from a for-loop in JavaScript beyond its scope

Hello there! Within nested json-files, I have been utilizing the following function for iteration: function organizePeopleGroups(People, container, parentObject) { _.each(People, function (item, index) { var peopleGuid =[]; for (var p ...

The statusText variable for getXMLHTTP object is not found when the status is not equal to

Earlier, I posted about this issue before isolating the problem. Now that I have isolated it, I wanted to repost with a clearer focus on the two functions causing the problem. Whenever I update my State, it triggers the getCity function. The call is being ...

Issue with Vue router - Multiple calls to the "next" callback were detected within one navigation guard

I have incorporated Vue 3 with Vue router 4 and have implemented middleware functions that my routes must pass through. However, I am encountering an error in Vue that states: The "next" callback was invoked multiple times in a single navigation guard wh ...

Can you explain the meaning of the symbol >>=?

I'm confused about the meaning of >>= (I thought it was greater than or equal to as >=). Can you also explain what (times & 1) means in the code snippet below? function repeat (string, times) { var result = '' while (times > 0) ...

The texture of various shapes in ThreeJS isn't functioning as expected

I have been experimenting with dynamic textures on threejs and I've noticed that when using different shapes, the texture does not work as expected. However, when I use boxGeometry, everything seems to be working perfectly. setCanvas =()=>{ th ...

designing a visually appealing pre-loader page that appears before the content loads

I am attempting to recreate the loading animation from this page. When the page loads, an SVG and background image appear, but once the user starts scrolling, the page quickly moves to the actual content and the loader is no longer visible or accessible ...

Creating a mat-tree component in Angular Material 6.0.1: Step-by-step guide

I am encountering an issue with my material angular mat-tree based application. The code runs without errors, but the values are not displayed on the screen. I need help resolving this problem so that I can proceed with the development. Upon opening the a ...

What are the reasons behind the absence of CORS issue on the backend server?

I have been working on a fun project using Vue and ran into a CORS issue when making api requests with axios from the front end. Can anyone provide some insight? Access to XMLHttpRequest at '...' from origin 'http://localhost:8080' ...

The challenge with the Optional Chaining operator in Typescript 3.7@beta

When attempting to utilize the Typescript optional chaining operator, I encountered the following exception: index.ts:6:1 - error TS2779: The left-hand side of an assignment expression may not be an optional property access. Here is my sample code: const ...

Planes in Three.js that are overflowing may have their opacity adjusted

My current challenge involves aligning two planes in the same (or closest possible) position. When two planes made of different materials and colors occupy the same space, depending on the camera angle and view perspective, the front plane's opacity ...

Error in Angular 4: Undefined property 'replace' causing trouble

I've been trying to use the .replace() JavaScript function in Angular 4 to remove certain characters from a string. Here is the code snippet from my component: @Component({...}) export class SomeComponent implements OnInit { routerUrl: string = &apo ...

Sign up for a Jquery template event

When utilizing a jquery template, the following HTML markup is being used: <div id="results"> <div class="CommentItem" commentid="33064" id="33064" data-guid="/Profile/Profile.aspx?id=Charliedog33"> <div class="CommentPic" ...

Create a regular expression that permits a sequence of numbers (either integer or decimal) arranged in groups of up to five, with each

Is it possible to create a regular expression that allows integers and decimals? var reg = /^((\s*)|([0-9]\d{0,9}(\.\d{1,3})?%?$))$/.; How can users input 0 to 5 groups of integers and decimals separated by |? Updated: This regex sh ...

The operation malfunctions if the variable input is below 50, causing it to produce inaccurate results

The function "calcFinalTotal()" was created to calculate the post-tax discount on a purchase of items that were previously totaled and stored in an input tag with the ID of "totaltaxamount". This function applies a 10% discount to orders between $50 to $ ...