Skip to content
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

Window and Document Objects Expected #18

Open
jonathansampson opened this issue Mar 4, 2021 · 2 comments
Open

Window and Document Objects Expected #18

jonathansampson opened this issue Mar 4, 2021 · 2 comments

Comments

@jonathansampson
Copy link
Contributor

jonathansampson commented Mar 4, 2021

For anybody attempting to use publicsuffixlist.js today, you'll encounter errors when window and document aren't found:

D:\Tests\node_modules\publicsuffixlist\publicsuffixlist.js:559
        const url = new URL(document.currentScript.src);
                            ^

ReferenceError: document is not defined
    at D:\Tests\node_modules\publicsuffixlist\publicsuffixlist.js:559:29
    at D:\Tests\node_modules\publicsuffixlist\publicsuffixlist.js:627:3
    at Object.<anonymous> (D:\Tests\node_modules\publicsuffixlist\publicsuffixlist.js:668:3)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Module.require (internal/modules/cjs/loader.js:965:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\Tests\index.js:17:20)
PS D:\Tests>

I stubbed out a simple document object (only that which was needed to get the utility working) and nulled a window object:

window = null;
document = {
    currentScript: {
        src: "file://"
    }
};

const suffixlist = require("publicsuffixlist");
const punycode = require("punycode/");
@gorhill
Copy link
Owner

gorhill commented Mar 5, 2021

I don't know much about how to correctly craft node packages, what would be the proper way to fix this?

@jonathansampson
Copy link
Contributor Author

@gorhill Shortest route is probably to replace these calls with a bit of feature detection to determine whether you're in a browser context, or a nodejs context. If the latter is the case, leverage node apis to perform similar logic. I would also look into Webpack and/or Browserify, as they may dramatically reduce friction as well, provided you would still like to support both a browser context, and a node context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants