-
Notifications
You must be signed in to change notification settings - Fork 112
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
fix: support esbuild #166
fix: support esbuild #166
Conversation
Thanks for the submission! In order to use as esm your |
your packge default export is https://github.com/taoqf/node-html-parser/blob/main/src/index.ts#L3 is a function export { default as parse, default } from './parse'; but in https://github.com/taoqf/node-html-parser/blob/main/esm/index.js#L1 import nhp from '../dist/index.js' and at Object.defineProperty(exports, "__esModule", { value: true }); and at Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(parse_1).default; } }); so esbuild will use so |
I need run |
The issue is that package exports are handled differently between ESM and CommonJS.
In ESM, the same statement means: import the entire module namespace and name it Our structure for ESM support follows the proper convention and is not buggy. You can see more detail in this PR:
It looks like you don't actually need to be using ESM. If you build to commonJS, you should be fine. I tried your exact reproduction, and I don't actually experience any issue: npm i esbuild node-html-parser typescript
echo 'import { parse, HTMLElement } from "node-html-parser";console.log({ parse, HTMLElement });' > test.ts
npx esbuild test.ts --bundle --outfile=test.js
node test.js
{
parse: [Function: parse],
HTMLElement: [class HTMLElement extends Node]
} Do you have a |
tsconfig.json in my project https://github.com/lisonge/visit-counter.git this project will show a bug, If you don't modify you see bug by following shell
|
my shell Log ❯ cat typescript
Script started on 2021-10-20 10:26:37+08:00 [TERM="xterm-256color" TTY="/dev/pts/0" COLUMNS="120" LINES="30"]
❯ ls -a .
. .. install.sh typescript
❯ cat install.sh
npm i esbuild node-html-parser typescript
echo 'import { parse, HTMLElement } from "node-html-parser";console.log({ parse, HTMLElement });' > test.ts
npx esbuild test.ts --bundle --outfile=test.js
node test.js
❯ ./install.sh
> [email protected] postinstall /home/lisonge/project/test/node_modules/esbuild
> node install.js
npm WARN saveError ENOENT: no such file or directory, open '/home/lisonge/project/test/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-freebsd-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"freebsd","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-freebsd-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"freebsd","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-linux-arm):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux","arch":"arm"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-darwin-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-android-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"android","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-linux-32):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux","arch":"ia32"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-linux-mips64le):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux","arch":"mips64el"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-darwin-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-linux-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-linux-ppc64le):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux","arch":"ppc64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-netbsd-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"netbsd","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-openbsd-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"openbsd","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-sunos-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"sunos","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-windows-32):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"win32","arch":"ia32"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-windows-64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"win32","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild/node_modules/esbuild-windows-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"win32","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN enoent ENOENT: no such file or directory, open '/home/lisonge/project/test/package.json'
npm WARN test No description
npm WARN test No repository field.
npm WARN test No README data
npm WARN test No license field.
+ [email protected]
+ [email protected]
+ [email protected]
added 14 packages from 7 contributors and audited 30 packages in 2.238s
8 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
╭───────────────────────────────────────────────────────────────╮
│ │
│ New major version of npm available! 6.14.15 → 8.1.0 │
│ Changelog: https://github.com/npm/cli/releases/tag/v8.1.0 │
│ Run npm install -g npm to update! │
│ │
╰───────────────────────────────────────────────────────────────╯
test.js 322.4kb
⚡ Done in 18ms
{ parse: undefined, HTMLElement: undefined }
❯ exit
Script done on 2021-10-20 10:27:04+08:00 [COMMAND_EXIT_CODE="0"]
|
i try ❯ npx esbuild test.ts --bundle --outfile=test.js --platform=node
test.js 313.1kb
⚡ Done in 19ms
❯ node test.js
{ parse: undefined, HTMLElement: undefined } |
Ok. I cloned your repo and had a look. A few observations:
It works for me with both $ npx esbuild test/test_import.ts --bundle --outfile=dist/test_import.js
dist\test_import.js 300.2kb
Done in 55ms
$ node dist/test_import.js
{
parse: [Function: parse],
HTMLElement: [class HTMLElement extends Node]
}
$ npx esbuild test/test_import.ts --bundle --outfile=dist/test_import.js --platform=node
dist\test_import.js 310.9kb
Done in 115ms
$ node dist/test_import.js
{ parse: [Function: parse2], HTMLElement: [Function: HTMLElement3] } I recommend the following:
If there is an issue beyond that, it's with Good luck with it! I hope you get it sorted out. |
i try run shell code at github actions
can you show |
@nonara |
Here's my file: https://gist.github.com/nonara/67ef1505a98a2c9ad02bf4ab06f0b183 I'd love to be able to help you track this out, but unfortunately I'm swamped. With that said, hopefully this will help point you in the right direction:
Given the discrepancy between your build failing and mine not, my best guess is that there is an issue between windows and unix. Recommended steps:
Again, I've confirmed that this is not an issue with our esm wrapper, as we followed the proper convention, and it works in both commonjs and esm environments. Good luck with it, and I hope you get it sorted out! |
I think the reason should be this because https://github.com/taoqf/node-html-parser/blob/main/tsconfig.json#L24
generate https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js#L5
this line code mark current file is cjs that compiled from esm, it can help keep connection between es modules in cjs runtime when esm import cjs in nodejs runtime, it doesn't depend on but esbuild will depend on and when i change for your this
I can't reproduce it at the moment, so i do not know |
This is standard output. File an issue with |
fix the following bug
will be output
{ parse:undefined, HTMLElement:undefined }