Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#14375 closed bug (fixed)

jquery-ui "requirable" as CJS module

Reported by: G-rom Owned by: G-rom
Priority: minor Milestone: 1.12.0
Component: [meta] ui.build Version: 1.11.4
Keywords: Cc:
Blocked by: Blocking:

Description

Hi,

Tools like webpack (or browserify, or ...) allow us to use a great range of module syntax (AMD, CJS, global, event ES6 with babel-loader) but

1/ jquery-ui is not up to date on npm see #11101 2/ jquery-ui package.json is not correct and it's missing a "main" section, i.e. "main": "./ui/core.js" or an "index.js" file / module at the root. With this fixed, jquery-ui cannot be required inside a project using modern project builder.

Would appreciate an update of package.json, at least #11101 can be by-passed by using github tarball url, but this one cannot by passed without a fork.

Change History (9)

comment:1 Changed 2 years ago by G-rom

Hi,

Tools like webpack (or browserify, or ...) allow us to use a great range of module syntax (AMD, CJS, global, event ES6 with babel-loader) but

1/ jquery-ui is not up to date on npm see #11101

2/ jquery-ui package.json is not correct and it's missing a "main" section, i.e. "main": "./ui/core.js" or an "index.js" file / module at the root. Without this fixed, jquery-ui cannot be required inside a project using modern project builder.

Would appreciate an update of package.json, at least #11101 can be by-passed by using github tarball url, but this one cannot by passed without a fork.

comment:2 Changed 2 years ago by Scott González

Owner: set to G-rom
Status: newpending

There is no main file for jQuery UI. Please clearly explain what you're looking for, or open a PR that shows the requested changes.

comment:3 Changed 2 years ago by G-rom

Status: pendingnew

I know there is no main file, but a valid package.json must have one. So you should have a valid package.json or no package.json file at all. In this current state, we cannot use npm & jquery-ui github tarball release

Solutions:

1/ removing the package.json

2/ fix the package.json & add a "main" entry

3/ add an "index.js" module at the package root, seems like it's the default "main" for npm package, but this solution is kind of hackish

comment:4 in reply to:  3 Changed 2 years ago by Scott González

Status: newpending

Replying to G-rom:

I know there is no main file, but a valid package.json must have one. So you should have a valid package.json or no package.json file at all. In this current state, we cannot use npm & jquery-ui github tarball release

We do have a valid package.json. The main field is *not* required, only name and version are.

Solutions:

1/ removing the package.json

Not at all a solution, we absolutely need package.json, it is our dependency manager.

2/ fix the package.json & add a "main" entry

There's no reasonable entry to add that has been proposed.

3/ add an "index.js" module at the package root, seems like it's the default "main" for npm package, but this solution is kind of hackish

Definitely a hack, especially if it does nothing.

comment:5 Changed 2 years ago by G-rom

Status: pendingnew

a "main" entry is not required, if you have an index.js

Keep rejecting all the solutions and jquery-ui will remain unusable by builder relying on node require resolving logic.

Another solution could be to add an index.js which will export a simple object listing all "ui" modules, like

module.exports = {
  accordion: require('./ui/accordion'),
  autocomplete: require('./ui/autocomplete'),
  ...

};

comment:6 Changed 2 years ago by G-rom

In fact, this could be the best solution, this way someone could do

var ui = require('jquery-ui');
var autocomplete = ui.autocomplete

or

var autocomplete = require('jquery-ui/ui/autocomplete');

for a fine grain load and a lighter build

comment:7 Changed 2 years ago by Scott González

comment:8 Changed 2 years ago by Jörn Zaefferer

Resolution: fixed
Status: newclosed

Build: Add main entry for webpack support; actual value doesn't matter

Fixes #14375 Closes gh-1600

Changeset: 6308a261fd5d1be2362863e6a59fede4420d9f8c

comment:9 Changed 2 years ago by Scott González

Milestone: none1.12.0
Note: See TracTickets for help on using tickets.