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

Can we save the word "unique"?

Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?

Can you grapple/shove with the Hunter Ranger's Whirlwind Attack?

Would combining A* with a flocking algorithm be too performance-heavy?

Why don't we use Cavea-B

The teacher logged me in as administrator for doing a short task, is the whole system now compromised?

What can I do to keep a threaded bolt from falling out of it’s slot

How to compare two different formulations of a problem?

To "hit home" in German

Can you feel passing through the sound barrier in an F-16?

What professions would a medieval village with a population of 100 need?

Thread-safe, Convenient and Performant Random Number Generator

Why doesn't mathematics collapse even though humans quite often make mistakes in their proofs?

Can pay be witheld for hours cleaning up after closing time?

Is it allowable to use an organization's name to publish a paper in a conference, even after I graduate from it?

Was Switzerland really impossible to invade during WW2?

Why were movies shot on film shot at 24 frames per second?

Starships without computers?

Are there reliable, formulaic ways to form chords on the guitar?

Why would the US President need briefings on UFOs?

Does C++20 mandate source code being stored in files?

Importing ES6 module in LWC project (sfdx)

Why we don't have vaccination against all diseases which are caused by microbes?

How to "know" if I have a passion?



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;








1















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










share|improve this question



















  • 1





    can you show relative code?

    – salesforce-sas
    8 hours ago

















1















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










share|improve this question



















  • 1





    can you show relative code?

    – salesforce-sas
    8 hours ago













1












1








1








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 8 hours ago









ShaiShai

1174 bronze badges




1174 bronze badges










  • 1





    can you show relative code?

    – salesforce-sas
    8 hours ago












  • 1





    can you show relative code?

    – salesforce-sas
    8 hours ago







1




1





can you show relative code?

– salesforce-sas
8 hours ago





can you show relative code?

– salesforce-sas
8 hours ago










2 Answers
2






active

oldest

votes


















4














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.






share|improve this answer


































    2














    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.






    share|improve this answer





























      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
      );



      );













      draft saved

      draft discarded


















      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









      4














      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.






      share|improve this answer































        4














        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.






        share|improve this answer





























          4












          4








          4







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 8 hours ago

























          answered 8 hours ago









          salesforce-sassalesforce-sas

          6,1011 gold badge2 silver badges23 bronze badges




          6,1011 gold badge2 silver badges23 bronze badges


























              2














              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.






              share|improve this answer































                2














                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.






                share|improve this answer





























                  2












                  2








                  2







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 8 hours ago

























                  answered 8 hours ago









                  ytiqytiq

                  5833 silver badges18 bronze badges




                  5833 silver badges18 bronze badges






























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                      Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                      François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480