Importing ES6 module in LWC project (sfdx)Lightning Web Components Easy Spaces sample application LWC component codevscode/sfdx doesn't see my projectlwc: sfdx unable to retrieve lwc filesImport ES modules in LWCLWC - Unit Testing NavigationMixin.GenerateUrlimport es6 from an extra javascript file in another component bundle in LWC'git' is not recognized as an internal or external command with salesforce cli
What are the pros and cons of Einstein-Cartan Theory?
Overwrite file only if data
Church Booleans
Why does my house heat up, even when it's cool outside?
Is it appropriate for a prospective landlord to ask me for my credit report?
Vacuum collapse -- why do strong metals implode but glass doesn't?
Why didn’t Doctor Strange stay in the original winning timeline?
Are illustrations in novels frowned upon?
Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?
Taking out number of subarrays from an array which contains all the distinct elements of that array
Is there such a thing as too inconvenient?
Can I submit a paper under an alias so as to avoid trouble in my country?
Starships without computers?
Metal that glows when near pieces of itself
Why would the US President need briefings on UFOs?
How to "know" if I have a passion?
Why doesn't mathematics collapse even though humans quite often make mistakes in their proofs?
Was 'help' pronounced starting with a vowel sound?
How to think about joining a company whose business I do not understand?
Ask for a paid taxi in order to arrive as early as possible for an interview within the city
Can pay be witheld for hours cleaning up after closing time?
How to avoid using System.String with Rfc2898DeriveBytes in C#
Can we save the word "unique"?
(Why) May a Beit Din refuse to bury a body in order to coerce a man into giving a divorce?
Importing ES6 module in LWC project (sfdx)
Lightning Web Components Easy Spaces sample application LWC component codevscode/sfdx doesn't see my projectlwc: sfdx unable to retrieve lwc filesImport ES modules in LWCLWC - Unit Testing NavigationMixin.GenerateUrlimport es6 from an extra javascript file in another component bundle in LWC'git' is not recognized as an internal or external command with salesforce cli
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Trying to do something relatively simple.
I've 2 LWC component under the lwc folder: lwc/cmp1 and lwc/cmp2
How can I create a new ES6 module that will serve as a utils.js file and then import it to each of cmp1 and cmp2?
I tried creating the utils.js file on cmp1 folder but couldn't import it to cmp2. Tried creating a new folder under lwc folder but it still didn't work (can't import).
The error I keep on getting is:
force-app/main/default/lwc/utils/utils.js LWC1011: Failed to resolve import "../utils/utils" from "cmp1.js". Please add "../utils/utils" file to the component folder.
There is no problem with the path given, VSCode easily find the related path and indicates no errors, only when trying to deploy to Salesforce
salesforcedx lightning-web-components
add a comment |
Trying to do something relatively simple.
I've 2 LWC component under the lwc folder: lwc/cmp1 and lwc/cmp2
How can I create a new ES6 module that will serve as a utils.js file and then import it to each of cmp1 and cmp2?
I tried creating the utils.js file on cmp1 folder but couldn't import it to cmp2. Tried creating a new folder under lwc folder but it still didn't work (can't import).
The error I keep on getting is:
force-app/main/default/lwc/utils/utils.js LWC1011: Failed to resolve import "../utils/utils" from "cmp1.js". Please add "../utils/utils" file to the component folder.
There is no problem with the path given, VSCode easily find the related path and indicates no errors, only when trying to deploy to Salesforce
salesforcedx lightning-web-components
1
can you show relative code?
– salesforce-sas
9 hours ago
add a comment |
Trying to do something relatively simple.
I've 2 LWC component under the lwc folder: lwc/cmp1 and lwc/cmp2
How can I create a new ES6 module that will serve as a utils.js file and then import it to each of cmp1 and cmp2?
I tried creating the utils.js file on cmp1 folder but couldn't import it to cmp2. Tried creating a new folder under lwc folder but it still didn't work (can't import).
The error I keep on getting is:
force-app/main/default/lwc/utils/utils.js LWC1011: Failed to resolve import "../utils/utils" from "cmp1.js". Please add "../utils/utils" file to the component folder.
There is no problem with the path given, VSCode easily find the related path and indicates no errors, only when trying to deploy to Salesforce
salesforcedx lightning-web-components
Trying to do something relatively simple.
I've 2 LWC component under the lwc folder: lwc/cmp1 and lwc/cmp2
How can I create a new ES6 module that will serve as a utils.js file and then import it to each of cmp1 and cmp2?
I tried creating the utils.js file on cmp1 folder but couldn't import it to cmp2. Tried creating a new folder under lwc folder but it still didn't work (can't import).
The error I keep on getting is:
force-app/main/default/lwc/utils/utils.js LWC1011: Failed to resolve import "../utils/utils" from "cmp1.js". Please add "../utils/utils" file to the component folder.
There is no problem with the path given, VSCode easily find the related path and indicates no errors, only when trying to deploy to Salesforce
salesforcedx lightning-web-components
salesforcedx lightning-web-components
asked 10 hours ago
ShaiShai
1174 bronze badges
1174 bronze badges
1
can you show relative code?
– salesforce-sas
9 hours ago
add a comment |
1
can you show relative code?
– salesforce-sas
9 hours ago
1
1
can you show relative code?
– salesforce-sas
9 hours ago
can you show relative code?
– salesforce-sas
9 hours ago
add a comment |
2 Answers
2
active
oldest
votes
You should not use "../utils/utils" for imports from modules. It should be 'c/utils'.
Implementation:
Create utils module:
sfdx force:lightning:component:create --type lwc -n utils -d force-app/main/default/lwc
Delete utils.html file.
Put below code in utils.js:
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Now deploy this module:
sfdx force:source:deploy -p force-app/main/default/lwc/utils
Now, in your component cmp1 which is already created and deployed, import above utils module like below:
import getTermOptions, calculateMonthlyPayment from 'c/utils';
Now, you can use getTermOptions() inside the class of cmp1.js file.
add a comment |
you need to create service component (component without *.html file).
Here is the example from documentation.
Your utils file.
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Your import statement in cmp1 or cmp2.
import getTermOptions, calculateMonthlyPayment from 'c/mortgage';
For more information follow LWC documentation provided earlier and spec for import statements.
Hopefully, that will help.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f274261%2fimporting-es6-module-in-lwc-project-sfdx%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should not use "../utils/utils" for imports from modules. It should be 'c/utils'.
Implementation:
Create utils module:
sfdx force:lightning:component:create --type lwc -n utils -d force-app/main/default/lwc
Delete utils.html file.
Put below code in utils.js:
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Now deploy this module:
sfdx force:source:deploy -p force-app/main/default/lwc/utils
Now, in your component cmp1 which is already created and deployed, import above utils module like below:
import getTermOptions, calculateMonthlyPayment from 'c/utils';
Now, you can use getTermOptions() inside the class of cmp1.js file.
add a comment |
You should not use "../utils/utils" for imports from modules. It should be 'c/utils'.
Implementation:
Create utils module:
sfdx force:lightning:component:create --type lwc -n utils -d force-app/main/default/lwc
Delete utils.html file.
Put below code in utils.js:
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Now deploy this module:
sfdx force:source:deploy -p force-app/main/default/lwc/utils
Now, in your component cmp1 which is already created and deployed, import above utils module like below:
import getTermOptions, calculateMonthlyPayment from 'c/utils';
Now, you can use getTermOptions() inside the class of cmp1.js file.
add a comment |
You should not use "../utils/utils" for imports from modules. It should be 'c/utils'.
Implementation:
Create utils module:
sfdx force:lightning:component:create --type lwc -n utils -d force-app/main/default/lwc
Delete utils.html file.
Put below code in utils.js:
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Now deploy this module:
sfdx force:source:deploy -p force-app/main/default/lwc/utils
Now, in your component cmp1 which is already created and deployed, import above utils module like below:
import getTermOptions, calculateMonthlyPayment from 'c/utils';
Now, you can use getTermOptions() inside the class of cmp1.js file.
You should not use "../utils/utils" for imports from modules. It should be 'c/utils'.
Implementation:
Create utils module:
sfdx force:lightning:component:create --type lwc -n utils -d force-app/main/default/lwc
Delete utils.html file.
Put below code in utils.js:
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Now deploy this module:
sfdx force:source:deploy -p force-app/main/default/lwc/utils
Now, in your component cmp1 which is already created and deployed, import above utils module like below:
import getTermOptions, calculateMonthlyPayment from 'c/utils';
Now, you can use getTermOptions() inside the class of cmp1.js file.
edited 9 hours ago
answered 9 hours ago
salesforce-sassalesforce-sas
6,1011 gold badge2 silver badges23 bronze badges
6,1011 gold badge2 silver badges23 bronze badges
add a comment |
add a comment |
you need to create service component (component without *.html file).
Here is the example from documentation.
Your utils file.
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Your import statement in cmp1 or cmp2.
import getTermOptions, calculateMonthlyPayment from 'c/mortgage';
For more information follow LWC documentation provided earlier and spec for import statements.
Hopefully, that will help.
add a comment |
you need to create service component (component without *.html file).
Here is the example from documentation.
Your utils file.
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Your import statement in cmp1 or cmp2.
import getTermOptions, calculateMonthlyPayment from 'c/mortgage';
For more information follow LWC documentation provided earlier and spec for import statements.
Hopefully, that will help.
add a comment |
you need to create service component (component without *.html file).
Here is the example from documentation.
Your utils file.
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Your import statement in cmp1 or cmp2.
import getTermOptions, calculateMonthlyPayment from 'c/mortgage';
For more information follow LWC documentation provided earlier and spec for import statements.
Hopefully, that will help.
you need to create service component (component without *.html file).
Here is the example from documentation.
Your utils file.
// mortage.js
const getTermOptions = () =>
return [
label: '20 years', value: 20 ,
label: '25 years', value: 25 ,
];
;
const calculateMonthlyPayment = (principal, years, rate) =>
// Logic
;
export getTermOptions, calculateMonthlyPayment ;
Your import statement in cmp1 or cmp2.
import getTermOptions, calculateMonthlyPayment from 'c/mortgage';
For more information follow LWC documentation provided earlier and spec for import statements.
Hopefully, that will help.
edited 9 hours ago
answered 9 hours ago
ytiqytiq
5833 silver badges18 bronze badges
5833 silver badges18 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f274261%2fimporting-es6-module-in-lwc-project-sfdx%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
can you show relative code?
– salesforce-sas
9 hours ago