magic-akari / seamless-scroll-polyfill

Scroll Behavior polyfill
https://www.npmjs.com/package/seamless-scroll-polyfill
MIT License
159 stars 12 forks source link

"Use methods directly without patching" does not work on EdgeHTML unless dist folder is specified #89

Closed dakur closed 1 year ago

dakur commented 4 years ago

If I use

import { elementScrollIntoView } from "seamless-scroll-polyfill";

elementScrollIntoView(document.querySelector("#target"), { behavior: "smooth", block: "center", inline: "center" });

as stated in docs, I've got error SCRIPT1028: SCRIPT1028: Expected identifier, string or number in MS Edge 44 (EdgeHTML 18) pointing to line

image

Old Edge can not parse ... thus this error. If I change import to import {elementScrollIntoView} from 'seamless-scroll-polyfill/dist/es5/seamless.js'; instead it works, but types are gone, so I have to @ts-ignore the import.

Is there a solution to this or is it a bug?

Thanks.

magic-akari commented 4 years ago

It seems that you bundled the umd or esm version of code without transcoded.

This package provides es5 version code as the default option. And provides esm as an optimization option.

Did you use a packaging tool like webpack? And set resolve.mainFields to something likemodule. If this is the case, you need to transcode by yourself.

dakur commented 4 years ago

Sorry for late response.

Yes, I use webpack, but there is no resolve.mainFields set. Maybe some of these settings may affect it?

tsconfig.json:

{
    "compilerOptions": {
        "target": "es2015",
        "module": "es2015",
        "moduleResolution": "node",
        "sourceMap": true,
        "lib": [
            "dom", "es6", "dom.iterable", "scripthost",
            "es2016.array.include"
        ],

        "noImplicitAny": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "jsx": "react",
        "strict": true,
        "allowSyntheticDefaultImports": true
    },
    "exclude": [
        "node_modules",
        "vendor"
    ]
}

.babelrc:

{
    "plugins": [
        ["@babel/plugin-transform-runtime", {
            "useESModules": true
        }]
    ],
    "presets": [
        ["@babel/preset-env", {
            "modules": false,
            "useBuiltIns": "usage",
            "corejs": 3
        }]
    ]
}
magic-akari commented 1 year ago

fixed in d1d7e0163f3f60230860cbd872ab07fca3145f72

dakur commented 1 year ago

Thank you. We don't support EdgeHTML anymore, but maybe someone else will test it.