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

fix: fix vite build error #208

Closed
wants to merge 1 commit into from

Conversation

Pat1enceLos
Copy link

fix build error when use vite build:

import { parse } from 'node-html-parser'

// parse is not a function
parse(text);

@taoqf
Copy link
Owner

taoqf commented Aug 9, 2022

Thank you so much for your work.
I tried create a vite project and used with your code but I could not see any build error.
Could you please show me more clue?

@Pat1enceLos
Copy link
Author

Steps to reproduce:

  • vite build
  • vite preview
    image

@taoqf
Copy link
Owner

taoqf commented Aug 10, 2022

I tried in my vite project:

import { parse } from 'node-html-parser';

export default function MyComponent() {
	useEffect(() => {
		const a = parse('<div></div>');
		let b = a;
		console.log(b);
	}, []);
}

and it seems works well.

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"],
      "@pages/*": ["./pages/*"],
      "@static/*": ["./static/*"],
    },
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
    
  },
  "include": ["**/*.ts", "**/*.tsx","src"],
  // "include": ["src"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

image

@Pat1enceLos
Copy link
Author

I reproduced in Vite3 + Vue3 before.
So I tried a new project Vite3 + React18 and use your config file, but still got the error
Did you got the error in http://localhost:4173/ ?

image

@taoqf
Copy link
Owner

taoqf commented Aug 12, 2022

I'm really so sorry for that.
My mistake, I didn't browse the page.

You can try this:

import parse from 'node-html-parser';

@Pat1enceLos
Copy link
Author

import parse from 'node-html-parser;

It will not work in dev runtime by:

yarn dev

image

taoqf added a commit that referenced this pull request Aug 12, 2022
@taoqf
Copy link
Owner

taoqf commented Aug 12, 2022

I tried to fix this, but I am not sure this commit will cause trouble with #166 , so I published this in prepatch version.

@Pat1enceLos
Copy link
Author

Pat1enceLos commented Aug 15, 2022

I thought the reason maybe was:

// src/index.ts
export { default as parse, default } from './parse';

// esm/index.js
import nhp from '../dist/index.js' // nhp just stands for parse function
export const CommentNode = nhp.CommentNode;
export const HTMLElement = nhp.HTMLElement;
...

and I was a little bit confused, why should we bind attributes to parse function in v5.4.2-0:

parse.parse = baseParse;
parse.HTMLElement = HTMLElement;
parse.CommentNode = CommentNode;
parse.valid = valid;
parse.Node = Node;
parse.TextNode = TextNode;
parse.NodeType = NodeType;

and also why should there export default parse function
hoping for your replay :)

@taoqf
Copy link
Owner

taoqf commented Aug 26, 2022

why should we bind attributes to parse function in v5.4.2-0:
why should there export default parse function

I think some people would import this lib like this

import parse from ''node-html-parser;
// or
import { parse } from ''node-html-parser;

I would like both way would work.

Would v5.4.2-0 work for you?

@Pat1enceLos
Copy link
Author

Would v5.4.2-0 work for you?

Yes, it works well :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants