nodejieba icon indicating copy to clipboard operation
nodejieba copied to clipboard

Unexpected character '�' (1:0)

Open pengjinning opened this issue 7 years ago • 8 comments

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

pengjinning avatar Jun 05 '17 03:06 pengjinning

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

dcsan avatar Aug 17 '17 22:08 dcsan

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

linonetwo avatar Oct 26 '17 02:10 linonetwo

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

ghost avatar Dec 19 '17 08:12 ghost

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?

dcsan avatar Dec 19 '17 12:12 dcsan

@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. 🙂

abinavseelan avatar Feb 01 '18 09:02 abinavseelan

good find @abinavseelan can you send a PR 🗡

dcsan avatar Feb 01 '18 14:02 dcsan

@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.

linonetwo avatar Feb 02 '18 01:02 linonetwo

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] avatar Sep 07 '24 13:09 github-actions[bot]