Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
Quoting Ben Finney (2018-03-06 22:37:22) > Pirate Praveen writes: > > > On ചൊവ്വ 06 മാർച്ച് 2018 03:45 വൈകു, Ben Finney wrote: > > > Is that a bug in the Debian Webpack, or a bug in the Debian > > > Backbone, or a bug in the Debian jQuery? Or a bug in the Webpack > > > configuration I've shown above? > > > > Do you have node-jquery installed? I don't think it is a bug in > > webpack or jquery, because the combination work well in case of > > gitlab. > > The Debian ‘node-backbone’ package does not depend on ‘node-jquery’, yet > when Backbone is imported it needs jQuery. So this is a bug in the > Debian ‘node-backbone’ package? I suspect that would be an upstream bug - http://backbonejs.org/ says: > Backbone's only hard dependency is Underscore.js - Jonas -- * Jonas Smedegaard - idealist & Internet-arkitekt * Tlf.: +45 40843136 Website: http://dr.jones.dk/ [x] quote me freely [ ] ask before reusing [ ] keep private signature.asc Description: signature -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
Pirate Praveen writes: > On ചൊവ്വ 06 മാർച്ച് 2018 03:45 വൈകു, Ben Finney wrote: > > Is that a bug in the Debian Webpack, or a bug in the Debian > > Backbone, or a bug in the Debian jQuery? Or a bug in the Webpack > > configuration I've shown above? > > Do you have node-jquery installed? I don't think it is a bug in > webpack or jquery, because the combination work well in case of > gitlab. The Debian ‘node-backbone’ package does not depend on ‘node-jquery’, yet when Backbone is imported it needs jQuery. So this is a bug in the Debian ‘node-backbone’ package? The ‘node-backbone’ package “Suggests: libjs-jquery-lazyload”, so will typically not bring in that package. Because the Backbone package can't be imported without jQuery, is the bug then that ‘node-backbone’ should actually declare a dependency on jQuery? -- \ “Books and opinions, no matter from whom they came, if they are | `\ in opposition to human rights, are nothing but dead letters.” | _o__) —Ernestine Rose | Ben Finney -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
On ചൊവ്വ 06 മാർച്ച് 2018 03:45 വൈകു, Ben Finney wrote: > > With that configuration, Webpack finds Backbone, but then fails to find > jQuery (as needed by the Debian-installed Backbone package). > > = > $ webpack --config webpack.config.js > Hash: a9597112585b9ca5fb40 > Version: webpack 3.5.6 > Time: 248ms > AssetSize Chunks Chunk Names > app.js 129 kB 0 [emitted] main >[0] ./source/foo.js 34 bytes {0} [built] >[1] /usr/share/javascript/backbone/backbone.js 72.2 kB {0} [built] >[2] (webpack)/buildin/global.js 488 bytes {0} [built] >[3] /usr/share/javascript/underscore/underscore.js 52.9 kB {0} >[built] > > ERROR in /usr/share/javascript/backbone/backbone.js > Module not found: Error: Can't resolve 'jquery' in > '/usr/share/javascript/backbone' > @ /usr/share/javascript/backbone/backbone.js 17:4-21:6 > @ ./source/foo.js > = > > Is that a bug in the Debian Webpack, or a bug in the Debian Backbone, or > a bug in the Debian jQuery? Or a bug in the Webpack configuration I've > shown above? Do you have node-jquery installed? I don't think it is a bug in webpack or jquery, because the combination work well in case of gitlab. >> webpack, like other node tools (grunt, gulp) does not recognize global >> modules. So we need to provide this path manually. But we could make >> this path default with a patch in debian like we did for grunt and >> gulp, patches welcome. > > I don't understand the problem well enough to patch it. This is by way > of diagnosis so far; but yes, I would assume that the Debian-installed > packages should be found by the Debian-installed Webpack module > resolver. > Since it is not present in webpack upstream, you can file a wishlist bug. signature.asc Description: OpenPGP digital signature -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
Pirate Praveen writes: > On ചൊവ്വ 06 മാർച്ച് 2018 08:29 രാവിലെ, Ben Finney wrote: > > So, either the defaults as installed by Debian are not sufficient > > for Webpack to resolve the path of an installed NodeJS library; or I > > have misunderstood what you say. > > I had linked to an exact line of the sample configuration which you > seem to have missed. > > resolve: { > modules: ['/usr/lib/nodejs', '.'], > }, > resolveLoader: { > modules: ['/usr/lib/nodejs'], > }, Thank you. I add that to the Webpack configuration, which makes it look like: = $ cat webpack.config.js "use strict"; const path = require('path'); module.exports = { entry: './source/foo.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'app.js', }, resolve: { modules: ['/usr/lib/nodejs', '.'], }, resolveLoader: { modules: ['/usr/lib/nodejs'], }, }; = With that configuration, Webpack finds Backbone, but then fails to find jQuery (as needed by the Debian-installed Backbone package). = $ webpack --config webpack.config.js Hash: a9597112585b9ca5fb40 Version: webpack 3.5.6 Time: 248ms AssetSize Chunks Chunk Names app.js 129 kB 0 [emitted] main [0] ./source/foo.js 34 bytes {0} [built] [1] /usr/share/javascript/backbone/backbone.js 72.2 kB {0} [built] [2] (webpack)/buildin/global.js 488 bytes {0} [built] [3] /usr/share/javascript/underscore/underscore.js 52.9 kB {0} [built] ERROR in /usr/share/javascript/backbone/backbone.js Module not found: Error: Can't resolve 'jquery' in '/usr/share/javascript/backbone' @ /usr/share/javascript/backbone/backbone.js 17:4-21:6 @ ./source/foo.js = Is that a bug in the Debian Webpack, or a bug in the Debian Backbone, or a bug in the Debian jQuery? Or a bug in the Webpack configuration I've shown above? > webpack, like other node tools (grunt, gulp) does not recognize global > modules. So we need to provide this path manually. But we could make > this path default with a patch in debian like we did for grunt and > gulp, patches welcome. I don't understand the problem well enough to patch it. This is by way of diagnosis so far; but yes, I would assume that the Debian-installed packages should be found by the Debian-installed Webpack module resolver. -- \ Fry: “Take that, poor people!” Leela: “But Fry, you’re not | `\ rich.” Fry: “No, but I will be someday, and then people like | _o__) me better watch out!” —Futurama | Ben Finney -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
On ചൊവ്വ 06 മാർച്ച് 2018 08:29 രാവിലെ, Ben Finney wrote: > I believe this configuration just relies on Webpack and NodeJS to figure > out the path resolution: > > = > $ cat webpack.config.js > "use strict"; > const path = require('path'); > module.exports = { > entry: './source/foo.js', > output: { > path: path.resolve(__dirname, 'dist'), > filename: 'app.js', > }, > }; > = > > Webpack simply fails to find ‘backbone’: > So, either the defaults as installed by Debian are not sufficient for > Webpack to resolve the path of an installed NodeJS library; or I have > misunderstood what you say. > I had linked to an exact line of the sample configuration which you seem to have missed. resolve: { modules: ['/usr/lib/nodejs', '.'], }, resolveLoader: { modules: ['/usr/lib/nodejs'], }, webpack, like other node tools (grunt, gulp) does not recognize global modules. So we need to provide this path manually. But we could make this path default with a patch in debian like we did for grunt and gulp, patches welcome. signature.asc Description: OpenPGP digital signature -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
Pirate Praveen writes: > I think it is still better to require/import just 'backbone' Okay: = $ cat ./source/foo.js "use strict"; import 'backbone'; = > and let nodejs and webpack handle the path resolution. I believe this configuration just relies on Webpack and NodeJS to figure out the path resolution: = $ cat webpack.config.js "use strict"; const path = require('path'); module.exports = { entry: './source/foo.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'app.js', }, }; = Webpack simply fails to find ‘backbone’: = $ dpkg --list node-backbone | grep '^i' ii node-backbone 1.3.3~dfsg-3 all some Backbone for JavaScript applications - Node module $ webpack --config webpack.config.js Hash: ff84e9ffdf4f296d9c1d Version: webpack 3.5.6 Time: 48ms Asset Size Chunks Chunk Names app.js 2.65 kB 0 [emitted] main [0] ./source/foo.js 34 bytes {0} [built] ERROR in ./source/foo.js Module not found: Error: Can't resolve 'backbone' in '[…]/source' @ ./source/foo.js 3:0-18 = So, either the defaults as installed by Debian are not sufficient for Webpack to resolve the path of an installed NodeJS library; or I have misunderstood what you say. -- \“… no testimony can be admitted which is contrary to reason; | `\ reason is founded on the evidence of our senses.” —Percy Bysshe | _o__)Shelley, _The Necessity of Atheism_, 1811 | Ben Finney -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
On തിങ്കള് 05 മാർച്ച് 2018 03:25 രാവിലെ, Ben Finney wrote: > My understanding, from https://webpack.js.org/concepts/modules/> > the Webpack documentation about modules, is that it claims to support > the ‘require’ modules (so-called “AMD modules”). > > The ‘libjs-backbone’ package installs Backbone code that uses AMD-style > ‘require’ dependencies. I think you meant UMD (Universal Module) here. I think it is still better to require/import just 'backbone' and let nodejs and webpack handle the path resolution. > So, when I write code that uses ‘import’ to bring in Backbone, and the > Backbone code uses ‘require’ for its dependencies, that seems compatible > with Webpack if I understand the Webpack documentation. Or am I missing > something there? > In this case, you just need to tell webpack to resolve dependencies from /usr/lib/nodejs. See https://wiki.debian.org/Javascript/Nodejs#CA-55601b3ea46d08ca4081f3465bbf840faab73781_10 signature.asc Description: OpenPGP digital signature -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
Pirate Praveen writes: > On March 4, 2018 2:56:53 PM GMT+05:30, Ben Finney wrote: > >I have the ‘libjs-backbone’ package installed, and want to use it in > >some JavaScript code via an ES6 ‘import’ statement. > > As far as I understand, you have to write code targeting nodejs […] Thanks for the reply. My understanding, from https://webpack.js.org/concepts/modules/> the Webpack documentation about modules, is that it claims to support the ‘require’ modules (so-called “AMD modules”). The ‘libjs-backbone’ package installs Backbone code that uses AMD-style ‘require’ dependencies. So, when I write code that uses ‘import’ to bring in Backbone, and the Backbone code uses ‘require’ for its dependencies, that seems compatible with Webpack if I understand the Webpack documentation. Or am I missing something there? -- \ “Corporation, n. An ingenious device for obtaining individual | `\ profit without individual responsibility.” —Ambrose Bierce, | _o__) _The Devil's Dictionary_, 1906 | Ben Finney -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel
Re: [Pkg-javascript-devel] ES6 ‘import’ of Debian-installed module
On March 4, 2018 2:56:53 PM GMT+05:30, Ben Finney wrote: >Howdy all, > >How should I write JavaScript ‘import’ statements to import a module >installed by a Debian package? > >Now that ‘webpack’ is available in Unstable, I have installed it (into >a >Buster host, if that matters) and am trying to write ES6 ‘import’ >statements to import library modules. > >I have the ‘libjs-backbone’ package installed, and want to use it in >some JavaScript code via an ES6 ‘import’ statement. > >The following code:: > >import Backbone from '/usr/share/javascript/backbone/backbone.js'; > >causes the following error from Webpack: > As far as I understand, you have to write code targeting nodejs, ie, use node-backbone installed in /usr/lib/nodejs (I don't know if that binary package already exist, else you need to create it). import Backbone from backbone Webpack will use nodejs dependency resolution and bundle everything into an output file which you can serve to browser. But this is nothing specific to Debian and you might get a better answer searching for node+backbone. Or in general developing front end in JavaScript. You can also refer to gitlab package and see how it uses webpack. http://kroltech.com/2013/12/29/boilerplate-web-app-using-backbone-js-expressjs-node-js-mongodb/ https://speckyboy.com/node-js-for-front-end-developers/ Since node version in Debian does not support es6 imports yet (it is planned for nodejs 10), you have to use node-babel-loader as well. Check node-d3-zoom for an example. BTW rollup is also available in Debian now, so you have a choice of rollup or webpack. -- Sent from my Android device with K-9 Mail. Please excuse my brevity. -- Pkg-javascript-devel mailing list Pkg-javascript-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-javascript-devel