yanyiwu / nodejieba

"结巴"中文分词的Node.js版本
MIT License
3.06k stars 278 forks source link

Unexpected character '�' (1:0) #91

Closed pengjinning closed 4 weeks ago

pengjinning commented 7 years ago

node v8.0.0 + laravel v5.4 + vue v2.3.3 报错:

ERROR Failed to compile with 1 errors 11:42:52

error in ./~/.2.2.5@nodejieba/build/Release/nodejieba.node

Module parse failed: /Users/ningjinpeng/Sites/admin/node_modules/.2.2.5@nodejieba/build/Release/nodejieba.node Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)

@ ./~/.2.2.5@nodejieba/index.js 1:16-69 @ ./resources/assets/js/bootstrap.js

dcsan commented 7 years ago

could be a backspace? a lot of mixed text ends up with half characters that don't display frmo someone deleting one byte of a two-byte character

p4u1d34n commented 7 years ago

Getting the same error here too.

Node 8.4.0 Ionic 3

Uncaught Error: Module parse failed: ***/node_modules/nodejieba/build/Release/nodejieba.node Unexpected character '�' (1:0)

Any idea how to stop this ?

linonetwo commented 7 years ago

I can't use it in electron, same error. Have tried ./node_modules/.bin/electron-rebuild

ghost commented 6 years ago

Same problem with this ***/node_modules/nodejieba/build/Release/nodejieba.node file

dcsan commented 6 years ago

it's loading a binary file

Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)

I've seen those type of characters before when encoding gets messed up eg utf8 / shiftJIS. but not sure for binary files

is this a win/unix thing with the 'BOM' issue?

abinavseelan commented 6 years ago

@pengjinning @yanyiwu

Hey. I just ran into this issue while transpiling my server code.

Looks like it's failing because the library imports a .node file on line 1.

var nodejieba = require( __dirname + "/build/Release/nodejieba.node");

I fixed it by including the node-loader loader for .node files in my webpack.config.js file.

module: {
    rules: [
      {
        test: /\.node$/,
        use: 'node-loader',
      },
      // other loaders come after
  ]
}

This worked for me. Not sure if my use-case for this similar to yours but give this a try. 🙂

dcsan commented 6 years ago

good find @abinavseelan can you send a PR 🗡

linonetwo commented 6 years ago

@dcsan That cannot be fixed in nodejieba's side. To use it should change the config of project's webpack. Though, it still can't be used in electron.

github-actions[bot] commented 2 months ago

This issue has not been updated for over 5 years and will be marked as stale. If the issue still exists, please comment or update the issue, otherwise it will be closed after 7 days.

github-actions[bot] commented 4 weeks ago

This issue has been automatically closed due to inactivity. If the issue still exists, please reopen it.