Skip to content

fix: fix vite build error - #208

Closed
Pat1enceLos wants to merge 1 commit into
taoqf:mainfrom
Pat1enceLos:fix/vite-build
Closed

Pat1enceLos wants to merge 1 commit into
taoqf:mainfrom
Pat1enceLos:fix/vite-build

Conversation

@Pat1enceLos

Copy link
Copy Markdown

fix build error when use vite build:

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

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

@taoqf

taoqf commented Aug 9, 2022

Copy link
Copy Markdown
Owner

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
Copy Markdown
Author

Steps to reproduce:

  • vite build
  • vite preview
    image

@taoqf

taoqf commented Aug 10, 2022

Copy link
Copy Markdown
Owner

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
Copy Markdown
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

taoqf commented Aug 12, 2022

Copy link
Copy Markdown
Owner

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
Copy Markdown
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

taoqf commented Aug 12, 2022

Copy link
Copy Markdown
Owner

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

Pat1enceLos commented Aug 15, 2022 •

Copy link
Copy Markdown
Author

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

taoqf commented Aug 26, 2022

Copy link
Copy Markdown
Owner

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
Copy Markdown
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.

3 participants