-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] pkg.main, pkg.module are incompatible, so require("sortablejs") behaves differently under Rollup/Webpack #1891
Comments
I think option 3 sounds like the best option, but need to ensure no changes are breaking. I've also experienced troubles with this. So are Some information: |
Now with sortablejs@1.11.2-alpha.3 (did you mean to tag an alpha as latest?), $ npm i sortablejs
+ sortablejs@1.11.2-alpha.3
added 1 package and audited 1 package in 0.542s
found 0 vulnerabilities
$ node -e 'require("sortablejs")'
internal/modules/cjs/loader.js:328
throw err;
^
Error: Cannot find module '/tmp/test/node_modules/sortablejs/dist/sortable.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:320:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:533:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
at Function.Module._load (internal/modules/cjs/loader.js:742:27)
at Module.require (internal/modules/cjs/loader.js:964:19)
at require (internal/modules/cjs/helpers.js:88:18)
at [eval]:1:1
at Script.runInThisContext (vm.js:132:18)
at Object.runInThisContext (vm.js:309:38)
at Object.<anonymous> ([eval]-wrapper:10:26) {
code: 'MODULE_NOT_FOUND',
path: '/tmp/test/node_modules/sortablejs/package.json',
requestPath: 'sortablejs'
}
$ ls node_modules/sortablejs/dist
sortable.umd.js sortable.umd.js.map |
I meet the same question , how to solve it? |
I solved it by |
I'm pretty sure this was fixed by #1913, but looking closer it looks like I missed out on packaging Main.. Fixing now. |
Still broken in 1.11.2-alpha.4 in a sort of reversed way:
This time |
Yeah okay thank you for your effort. I'll fix it tomorrow, don't have my computer one me right now. |
Do we even need the main field? |
Without the |
@andersk Thank you for claryifying. Almost done fixing the screw ups btw |
* refactor: remove code formattings config files * docs: add more detail to contribution guidelines * docs: remove custom templates * docs: update bug report issue * docs: add discussion template * docs: update featue template * fix(build): build dist/sortablejs, was missing prior * build(deps): yarn upgrade * v1.11.2-alpha.4 * fix(build): exports modules correctly This was broken, visible, and closes #1891.
Thanks for your attention to this, but it’s still broken in 1.12.0; it’s back to what I wrote in the original description. Please reopen this. |
@andersk How about now? I removed the module and it now just Main. |
I expect that will work. |
In some environments like Node and Browserify,
require("sortablejs")
returnsSortable
, but in others like Rollup and Webpack,require("sortablejs")
returns a module{ Sortable: Sortable, default: Sortable, … }
. This means a SortableJS dependent can’t be compatible with these different environments without contortions.This is because Node and Browserify are using
pkg.main
(./Sortable.js
), while Rollup and Webpack are usingpkg.module
(modular/sortable.esm.js
), and the two files do not provide compatible interfaces.This problem is called out in the Rollup documentation:
Three potential solutions are:
named
export mode, sorequire("sortablejs").default
orrequire("sortablejs").Sortable
would work everywhere; orSortable.default = Sortable
and/orSortable.Sortable = Sortable
for compatibility; orpkg.module
.Information
Versions - Look in your
package.json
for this information:sortablejs = ^1.10.2
The text was updated successfully, but these errors were encountered: