<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Importing .scss files inside TS React components with liferay npm bu</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121504205" />
  <subtitle>Importing .scss files inside TS React components with liferay npm bu</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121504205</id>
  <updated>2026-04-05T23:48:09Z</updated>
  <dc:date>2026-04-05T23:48:09Z</dc:date>
  <entry>
    <title>RE: Importing .scss files inside TS React components with liferay npm bu</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121511442" />
    <author>
      <name>Roselaine Marques</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121511442</id>
    <updated>2022-09-14T13:56:58Z</updated>
    <published>2022-09-12T07:59:46Z</published>
    <summary type="html">&lt;p&gt;Hi, &lt;/p&gt;
&lt;p&gt;Did you install the dev dependencies necessary for the loaders?&lt;/p&gt;
&lt;p&gt;You can see the step by step here: &lt;/p&gt;
&lt;p&gt;https://liferay.dev/es/blogs/-/blogs/how-to-use-sass-in-react-widget-liferay-1&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Roselaine Marques</dc:creator>
    <dc:date>2022-09-12T07:59:46Z</dc:date>
  </entry>
  <entry>
    <title>Importing .scss files inside TS React components with liferay npm bu</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121504204" />
    <author>
      <name>Valentin Eggermont</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121504204</id>
    <updated>2022-08-29T15:02:54Z</updated>
    <published>2022-08-27T16:00:07Z</published>
    <summary type="html">&lt;p&gt;Hi Liferay Devs !&lt;/p&gt;
&lt;p&gt;I'm trying to build a frontend module that contains React components
  written in Typescript so they could be reused through multiple portlet
  modules (so in that way, I don't need to copy each component code in
  every module that need it). I've got something that is perfectly
  working and that can be used on other modules by referencing my
  frontend module on their .npmbundlerrc file but now I'm also trying to
  use and import seperated .scss for the styling of each component
  instead of copy/pasting each time the styling in each module's css.
  After many tries I didn't manage to...&lt;/p&gt;
&lt;p&gt;I tried to create a Test component with the following code : &lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-javascript"&gt;import React from 'react';

import &amp;quot;./Test.scss&amp;quot;;

interface TestProps {
    text: string
}

const Test: React.FC&amp;lt;TestProps&amp;gt; = ({text}) =&amp;gt; {

    return &amp;lt;span className=&amp;quot;test&amp;quot;&amp;gt;{text}&amp;lt;/span&amp;gt;
}

export default Test;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see I invoked a .scss that contains the styling for this
  component. In order to get the scss translated to css and bundled in
  Liferay JS Loader, I used Liferay NPM Bundler loaders in my
  .npmbundlerrc file:  &lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;{  
  ...
  &amp;quot;rules&amp;quot;: [
    {
      &amp;quot;test&amp;quot;: &amp;quot;\\.scss$&amp;quot;,
      &amp;quot;use&amp;quot; : [ &amp;quot;sass-loader&amp;quot;, &amp;quot;style-loader&amp;quot;, &amp;quot;css-loader&amp;quot;]
    }
  ]
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However doesn't look like my css is bundled into Liferay JS Loader
  like it supposed to be according to these loaders documentation. The
  component's bundled code still invoke the .scss file without Liferay
  loader. Here's the result in the Test.js built : &lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-javascript"&gt;&amp;quot;use strict&amp;quot;;

Liferay.Loader.define(&amp;quot;test-frontend@1.0.0/components/Test&amp;quot;, ['module', 'exports', 'require', 'liferay!frontend-js-react-web$react', './Test.scss'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, &amp;quot;__esModule&amp;quot;, {
      value: true
    });
    exports[&amp;quot;default&amp;quot;] = void 0;

    var _react = _interopRequireDefault(require(&amp;quot;liferay!frontend-js-react-web$react&amp;quot;));

    require(&amp;quot;./Test.scss&amp;quot;);

    function _interopRequireDefault(obj) {
      return obj &amp;amp;&amp;amp; obj.__esModule ? obj : { &amp;quot;default&amp;quot;: obj };
    }

    var Test = function Test(_ref) {
      var text = _ref.text;
      return (/*#__PURE__*/_react[&amp;quot;default&amp;quot;].createElement(&amp;quot;span&amp;quot;, {
          className: &amp;quot;test&amp;quot;
        }, text)
      );
    };

    var _default = Test;
    exports[&amp;quot;default&amp;quot;] = _default;
    //# sourceMappingURL=Test.js.map
  }
});
//# sourceMappingURL=Test.js.map&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So in the end, my css is not invoked and actually my component is not
  working as it's trying to import something that as not define in the
  loader and so doesn't exists. I've got the following error in my
  browser : &lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;Error: Unsatisfied dependency: ./Test.scss found in module test-frontend@1.0.0/components/Test
    at loader.js:689:15
    at Array.map (&amp;lt;anonymous&amp;gt;)
    at loader.js:671:59
    at Array.forEach (&amp;lt;anonymous&amp;gt;)
    at e.value (loader.js:633:34)
    at loader.js:414:10&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Do you have any idea of would be wrong ? I still would like to build
  this using liferay-npm-bundler (I don't want to use liferay-npm-script)&lt;/p&gt;
&lt;p&gt;Some additional hints on how my module is built : &lt;/p&gt;
&lt;p&gt;- I didn't create this module using Yeoman Liferay JS Generator and
  for some other technical reasons, I can't. It must be a classic module
  with .bnd file. I created it using Blade command line&lt;/p&gt;
&lt;p&gt;- Before running the liferay-npm-bundler command the .tsx file are
  built using Babel 7, here the npm command used when deploying the
  module : &lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;tsc &amp;amp;&amp;amp; babel --source-maps -d build/resources/main/META-INF/resources src/main/resources/META-INF/resources --extensions \&amp;quot;.ts,.tsx,.js,.jsx\&amp;quot; &amp;amp;&amp;amp; liferay-npm-bundler
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; Thanks a lot in advance for all you replies. &lt;/p&gt;</summary>
    <dc:creator>Valentin Eggermont</dc:creator>
    <dc:date>2022-08-27T16:00:07Z</dc:date>
  </entry>
</feed>
