Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay Frontend - npm builder : how to share JS ?
Dear community,
I wish I could integrate Liferay 7.1 GA2 with Splunk (http://www.splunk.com) using their SDK. Unfortunatelty, due to JS loader introduced since 7.0 and as the proposed JS from Splunk use AMD loader, it brings some conflicts. I need to package the splunk JS to use it properly in my portlets.
I have been following different tutorial but spent more time on the one share during the last devcon about Angular.
I initialized my liferay-npm-builder and added splunk-sdk as a dependency. As a result, I have:
My package.json
my .npmbundlerrc
The above configuration is provided by default using
And I selected "shared packages bundle"
Now, I deploy successfully this package to Liferay
And it looks like the OSGI module starts properly but I haven't found any way to check if my JS bundle is available somewhere...
Then, from another portlet, I try to refer to this new bundle in a JSP page
As you may notice, I try both ways and in any cases it says that this bundle doesn't exist. I don't know which syntax to follow and don't know where to find the list of bundles available.
I want to point to the splunk.js file available in the splunk-shared module folder
How should I proceed ?
Thank you in advance for your help,
I wish I could integrate Liferay 7.1 GA2 with Splunk (http://www.splunk.com) using their SDK. Unfortunatelty, due to JS loader introduced since 7.0 and as the proposed JS from Splunk use AMD loader, it brings some conflicts. I need to package the splunk JS to use it properly in my portlets.
I have been following different tutorial but spent more time on the one share during the last devcon about Angular.
I initialized my liferay-npm-builder and added splunk-sdk as a dependency. As a result, I have:
ecoquelin@kenitra:~/workspaces/splunk/splunk/modules/splunk-shared$ ll
total 300
drwxr-xr-x 8 ecoquelin ecoquelin 4096 janv. 29 22:20 ./
drwxr-xr-x 7 ecoquelin ecoquelin 4096 janv. 29 21:18 ../
drwxr-xr-x 2 ecoquelin ecoquelin 4096 janv. 29 21:18 assets/
-rw-r--r-- 1 ecoquelin ecoquelin 24 janv. 29 21:18 .babelrc
drwxr-xr-x 3 ecoquelin ecoquelin 4096 janv. 29 22:05 build/
drwxr-xr-x 2 ecoquelin ecoquelin 4096 janv. 29 21:27 dist/
drwxr-xr-x 3 ecoquelin ecoquelin 4096 janv. 29 21:18 features/
-rw-r--r-- 1 ecoquelin ecoquelin 61 janv. 29 21:18 .gitignore
-rw-r--r-- 1 ecoquelin ecoquelin 58112 janv. 29 22:20 liferay-npm-bundler-report.html
drwxr-xr-x 381 ecoquelin ecoquelin 20480 janv. 29 21:19 node_modules/
-rw-r--r-- 1 ecoquelin ecoquelin 73 janv. 29 21:18 .npmbuildrc
-rw-r--r-- 1 ecoquelin ecoquelin 230 janv. 29 22:20 .npmbundlerrc
-rw-r--r-- 1 ecoquelin ecoquelin 502 janv. 29 21:19 package.json
-rw-r--r-- 1 ecoquelin ecoquelin 169408 janv. 29 21:19 package-lock.json
-rw-r--r-- 1 ecoquelin ecoquelin 30 janv. 29 21:18 README.md
drwxr-xr-x 2 ecoquelin ecoquelin 4096 janv. 29 21:21 src/
My package.json
{
"name": "splunk-shared",
"version": "1.0.0",
"description": "Splunk Shared",
"devDependencies": {
"liferay-npm-bundler": "^2.6.1",
"liferay-npm-build-support": "^2.6.1",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0"
},
"dependencies": {
"splunk-sdk": "^1.8.4"
},
"scripts": {
"build": "babel --source-maps -d build src && npm run copy-assets && liferay-npm-bundler",
"copy-assets": "lnbs-copy-assets",
"deploy": "npm run build && lnbs-deploy"
},
"main": "index.js"
}
my .npmbundlerrc
{
"create-jar": {
"output-dir": "dist",
"features": {
"js-extender": false,
"web-context": "/splunk-shared",
"localization": "features/localization/Language"
}
},
"dump-report": true,
"process-serially": true
}
The above configuration is provided by default using
yo liferay-bundle
And I selected "shared packages bundle"
Now, I deploy successfully this package to Liferay
npm run deploy
And it looks like the OSGI module starts properly but I haven't found any way to check if my JS bundle is available somewhere...
Then, from another portlet, I try to refer to this new bundle in a JSP page
<aui:script require="splunk-shared">
/* Liferay.Loader.require('splunk-shared', function(splunkjs) {
console.log(splunkjs);
}, function(error) {
console.error(error);
});
*/
</aui:script>
As you may notice, I try both ways and in any cases it says that this bundle doesn't exist. I don't know which syntax to follow and don't know where to find the list of bundles available.
I want to point to the splunk.js file available in the splunk-shared module folder
modules/splunk-shared/node_modules/splunk-sdk/client/splunk.js
How should I proceed ?
Thank you in advance for your help,
I have been through another test using following syntax
I don't get anymore the problem saying that it doesn't know what splunk-shared is and have a bootstrap message I put in my index.js. But the console.log(...) is not displayed. I get the following error in the browser
It looks like it looks for the index.js.map but when I check the build/index.js (autogenerated from my index.js), I have
So it looks the map file is commented.
<aui:script require="splunk-shared@1.0.0">
console.log("splunkjs=" +splunkjs);
</aui:script>
I don't get anymore the problem saying that it doesn't know what splunk-shared is and have a bootstrap message I put in my index.js. But the console.log(...) is not displayed. I get the following error in the browser
Erreur dans les liens source : request failed with status 404 URL de la ressource : http://localhost:8080/combo/?browserId=firefox&minifierType=&languageId=en_US&b=7101&t=1548795097782&/o/js/resolved-module/frontend-js-metal-web@2.0.4/bridge/metal-dom/src/all/dom.js&/o/js/resolved-module/frontend-js-metal-web@2.0.4/bridge/metal-uri/src/Uri.js&/o/js/resolved-module/frontend-js-metal-web$metal-position@2.1.1/lib/Geometry.js&/o/js/resolved-module/frontend-js-metal-web$metal-position@2.1.1/lib/Position.js&/o/js/resolved-module/frontend-js-metal-web$metal-position@2.1.1/lib/Align.js&/o/js/resolved-module/frontend-js-metal-web$metal-position@2.1.1/lib/all/position.js&/o/js/resolved-module/frontend-taglib-clay$clay-tooltip@2.3.4/lib/ClayTooltip.soy.js&/o/js/resolved-module/frontend-taglib-clay$clay-tooltip@2.3.4/lib/ClayTooltip.js&/o/js/resolved-module/frontend-taglib-clay@1.2.4/bridge/clay-tooltip/src/ClayTooltip.js&/o/js/resolved-module/splunk-shared@1.0.0/index.js URL du lien source : index.js.map
It looks like it looks for the index.js.map but when I check the build/index.js (autogenerated from my index.js), I have
Liferay.Loader.define("splunk-shared@1.0.0/index", ['module', 'exports', 'require'], function (module, exports, require) {
var define = undefined;
console.log("bootstrapped splunk-shared");
//# sourceMappingURL=index.js.map
});
//# sourceMappingURL=index.js.map
So it looks the map file is commented.
The last but probably not the very last, when using
It looks it goes in the right direction but my browser shows the following messages
AND the same as before
<aui:script require="splunk-shared$splunk-sdk@1.8.4">
console.log("splunkjs=" +splunkjs);
</aui:script>
It looks it goes in the right direction but my browser shows the following messages
Error: "Error processing module: splunk-shared$readable-stream@2.0.6/lib/_stream_duplex. The provided configuration is not Directed Acyclic Graph."
AND the same as before
Erreur dans les liens source : request failed with status 404 URL de la ressource : http://localhost:8080/combo?browserId=firefox&minifierType=js&languageId=en_US&b=7101&t=1548795097782&/o/frontend-js-web/jquery/jquery.js&/o/frontend-js-web/clay/popper.js&/o/frontend-js-web/clay/bootstrap.js&/o/frontend-js-web/loader/config.js&/o/frontend-js-web/loader/loader.js&/o/frontend-js-web/lodash/lodash.js&/o/frontend-js-web/aui/aui/aui.js&/o/frontend-js-web/aui/aui-base-html5-shiv/aui-base-html5-shiv.js&/o/frontend-js-web/liferay/browser_selectors.js&/o/frontend-js-web/liferay/modules.js&/o/frontend-js-web/liferay/aui_sandbox.js&/o/frontend-js-web/clay/collapsible-search.js&/o/frontend-js-web/clay/side-navigation.js&/o/frontend-js-web/jquery/fm.js&/o/frontend-js-web/jquery/form.js&/o/frontend-js-web/lodash/util.js&/o/frontend-js-web/misc/svg4everybody.js&/o/frontend-js-web/aui/arraylist-add/arraylist-add.js&/o/frontend-js-web/aui/arraylist-filter/arraylist-filter.js&/o/frontend-js-web/aui/arraylist/arraylist.js&/o/frontend-js-web/aui/array-extras/array-extras.js&/o/frontend-js-web/aui/array-invoke/array-invoke.js&/o/frontend-js-web/aui/attribute-base/attribute-base.js&/o/frontend-js-web/aui/attribute-complex/attribute-complex.js&/o/frontend-js-web/aui/attribute-core/attribute-core.js&/o/frontend-js-web/aui/attribute-observable/attribute-observable.js&/o/frontend-js-web/aui/attribute-extras/attribute-extras.js&/o/frontend-js-web/aui/base-base/base-base.js&/o/frontend-js-web/aui/base-pluginhost/base-pluginhost.js&/o/frontend-js-web/aui/classnamemanager/classnamemanager.js&/o/frontend-js-web/aui/datatype-xml-format/datatype-xml-format.js&/o/frontend-js-web/aui/datatype-xml-parse/datatype-xml-parse.js&/o/frontend-js-web/aui/dom-base/dom-base.js&/o/frontend-js-web/aui/dom-core/dom-core.js&/o/frontend-js-web/aui/dom-screen/dom-screen.js&/o/frontend-js-web/aui/dom-style/dom-style.js&/o/frontend-js-web/aui/event-base/event-base.js&/o/frontend-js-web/aui/event-custom-base/event-custom-base.js&/o/frontend-js-web/aui/event-custom-complex/event-custom-complex.js&/o/frontend-js-web/aui/event-delegate/event-delegate.js URL du lien source : loader.js.map
Hi Eric:
As you have guessed, the proper require syntax is "splunk-shared$splunk-sdk@1.8.4". That is because your shared bundle is called "splunk-shared" and that namespaces "splunk-sdk" with the "splunk-shared$" prefix. You can find more about namespacing here:
Regarding the source map, it is not commented, that's the standard syntax:
And, to finish with, the "The provided configuration is not Directed Acyclic Graph" message means that you have circular dependencies in your setup which is a bad thing because we don't support it yet :-(. There are some workarounds with webpack and an issue to centralize all the information regarding that feature:
Hope this helps.
As you have guessed, the proper require syntax is "splunk-shared$splunk-sdk@1.8.4". That is because your shared bundle is called "splunk-shared" and that namespaces "splunk-sdk" with the "splunk-shared$" prefix. You can find more about namespacing here:
- https://github.com/liferay/liferay-npm-build-tools/wiki/Miscellaneous-resources#blog-posts
- https://github.com/liferay/liferay-npm-build-tools/wiki/How-Liferay-serves-npm-packages-to-the-browser#per-project-package-isolation-new-since-liferay-npm-bundler-2
Regarding the source map, it is not commented, that's the standard syntax:
And, to finish with, the "The provided configuration is not Directed Acyclic Graph" message means that you have circular dependencies in your setup which is a bad thing because we don't support it yet :-(. There are some workarounds with webpack and an issue to centralize all the information regarding that feature:
Hope this helps.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™