closest
closest copied to clipboard
webpack error: Unexpected token: name (element)
webpack production build (with minify) fails when element-closest
is imported:
import 'element-closest';
Unexpected token: name (element) [scripts/main_a637191f.js:8161,10]
I’m not sure that’s coming from me.
https://unpkg.com/[email protected]/index.js there is no name
variable.
this is likely due to using gulp-uglify (or another js minifier) which only supports es5
and this library uses es6
, i'd recommend checking out
- https://www.npmjs.com/package/gulp-uglify
- https://www.npmjs.com/package/uglify-es
- or using https://babeljs.io to convert your libraries to es5 prior to minification
with version v3.0.0
try using a named import like this
import elementClosest from "element-closest";
elementClosest(window);
Also the elementClosest(window);
is required to initialize the polyfill in Node (eg. with webpack, gulp etc)