Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  96] [ 6]  / answers: 1 / hits: 33728  / 7 Years ago, mon, august 14, 2017, 12:00:00

I am authoring a JavaScript library that I want to put on npm. I am currently using that library in another project and I have added it as a dependency using its GitHub repository:


"dependencies": {
// ... others
"react-web-component": "LukasBombach/react-web-component",
}

I am also using Webpack with the UglifyJsPlugin. Now when I want to build my project I get an error:



Failed to compile.


Failed to minify the code from this file:


./packages/react-scripts/node_modules/react-web-component/src/index.js line 18:0


Read more here: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify


error Command failed with exit code 1.



This is a problem of my library. When I remove it from my deps (and from my code) compiling works.


I cannot figure out what the problem is, my code seems pretty straight forward:


const ReactDOM = require('react-dom');
const retargetEvents = require('./retargetEvents');
const getStyleElementsFromReactWebComponentStyleLoader = require('./getStyleElementsFromReactWebComponentStyleLoader');

module.exports = {
create: function(app, tagName, options) {
const proto = Object.create(HTMLElement.prototype, {
attachedCallback: {
value: function() {
const shadowRoot = this.createShadowRoot();
const mountPoint = document.createElement('div');
getStyleElementsFromReactWebComponentStyleLoader().forEach(style =>
shadowRoot.appendChild(style)
);
shadowRoot.appendChild(mountPoint);
ReactDOM.render(app, mountPoint);
retargetEvents(shadowRoot);
},
},
});
document.registerElement(tagName, { prototype: proto });
},
};

Inside the retargetEvents and getStyleElementsFromReactWebComponentStyleLoader requires there are simple module.export commands. You can see their source code here and here.


I have already tried publishing my library using ES6 export / import commands.


The full source code of my library (it's just these 3 files) can be found at https://github.com/LukasBombach/react-web-component


More From » node.js

 Answers
13

I found the solution!



I had some ES6 features in my code, namely foreach the ~ operator and shorthand function syntax. The uglyfier did not accept that. I needed to replace that with ES5 code and it works well now.


[#56778] Thursday, August 10, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleykeyshawnb

Total Points: 281
Total Questions: 99
Total Answers: 111

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
mckinleykeyshawnb questions
;