-
Notifications
You must be signed in to change notification settings - Fork 40
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
Can't use after installing via npm (without webpack or similar) #113
Comments
Correct, the package is currently not pre-bundled for use in the browser, as the getting started page says: “Currently we only support installation through NPM packages. You will need to use a bundler (such as webpack) to use the modules in a web browser.” If there is demand for it, and apparently there is, this would be a nice thing to provide, either in the npm packages, or we could distribute bundled/browser-compatible packages separately. @tilgovi do you have ideas about this? What approaches we could take? |
It could run in the browser, if imports like these (ES6 imports instead of node imports) were generated:
This presumes that those babel imports also generate ES6 style module files. |
Maybe there is also a way to tell TypeScript (or which ever compiler is responsible) to generate ES6 module imports instead of node imports. |
We are generating ES6 imports/exports. We don't actually ship CommonJS at all right now. But npm package imports are not valid in the browser because the browser only allows imports from URLs (relative or absolute). I would have expected some of the CDNs that support bundling to work, like importing We can try to fix that, and we should absolutely consider more ways to package and ship, so we appreciate hearing what would be helpful and even more appreciate any help updating the packaging! |
Looks like that problem has been reported here: autarc/optimal-select#70 We could drop the "describe" support for Element -> CSS selector conversion, or try to find another package for that, or roll our own basic one. That package hasn't been updated since 2017. |
I propose we switch to @medv/finder. It is actively maintained (for now), written in TypeScript, seems properly packaged, has no dependencies, and has an MIT license. We could still consider shipping browser bundles, but at least this change should make it possible to load a browser bundle through a CDN like snowpack. |
There's a project that compares some of these CSS selector generation libraries, and it seems to find this one favorable, too: https://github.com/fczbkk/css-selector-generator-benchmark I checked out the code and it also looks like it support passing a document in explicitly—so it doesn't have any dependencies on globals—and passing in a root element—great for generating refining selectors. |
Regarding replacing the
|
Ah, I see. It shouldn't be a problem that It's easy to stop transforming the module syntax by changing our Babel configuration, but Mocha still won't recognize the Alternatively, we might compile our dependencies, or at least that one, which is a change we could make in our Babel config. |
Actually, even compiling the dependencies won't work, because I'll continue to work on this. |
Compile to ECMAScript module syntax for tests. - Replace nyt with c8 - Replace optimal-select with @medv/finder - Replace custom babel-register with babel-register-esm Close #113
The project can't be used in the browser after installing it via npm because the files reference
import _Object$keys from "@babel/runtime-corejs3/core-js/object/keys";
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
import _Array$from from "@babel/runtime-corejs3/core-js/array/from";
import _Symbol from "@babel/runtime-corejs3/core-js/symbol";
import _getIteratorMethod from "@babel/runtime-corejs3/core-js/get-iterator-method";
import _getIterator from "@babel/runtime-corejs3/core-js/get-iterator";
causing
Uncaught TypeError: Error resolving module specifier “@babel/runtime-corejs3/core-js/object/keys”. Relative module specifiers must start with “./”, “../” or “/”.
Solution:
Publish truly pre-compiled artifacts (e.g. annotator.min.js) on npm that can be used in the browser without webpack.
The text was updated successfully, but these errors were encountered: