atom / node-keytar

Native Password Node Module
https://atom.github.io/node-keytar
MIT License
1.37k stars 193 forks source link

ERROR: Unexpected character '�' #59

Closed dnichols closed 7 years ago

dnichols commented 7 years ago

Getting an error using keytar with this boilerplate during the build process:

ERROR in ./~/keytar/build/Release/keytar.node
Module parse failed: …/node_modules/keytar/build/Release/keytar.node Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '�' (1:0)
    at Parser.pp$4.raise (…/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp$7.getTokenFromCode (…/node_modules/webpack/node_modules/acorn/dist/acorn.js:2756:10)
    at Parser.pp$7.readToken (…/node_modules/webpack/node_modules/acorn/dist/acorn.js:2477:17)
    at Parser.pp$7.nextToken (…/node_modules/webpack/node_modules/acorn/dist/acorn.js:2468:15)
    at Parser.parse (…/node_modules/webpack/node_modules/acorn/dist/acorn.js:515:10)
    at Object.parse (…/node_modules/webpack/node_modules/acorn/dist/acorn.js:3098:39)
    at Parser.parse (…/node_modules/webpack/lib/Parser.js:902:15)
    at DependenciesBlock.<anonymous> (…/node_modules/webpack/lib/NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (…/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (…/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at …/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.finished (…/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at …/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:439:3)
 @ ./~/keytar/lib/keytar.js 4:11-50
dnichols commented 7 years ago

I wasn't using an appropriate loader { test: /\.node$/, loader: 'node-loader' } in webpack.config.base.js

tonyganch commented 7 years ago

@dnichols, thank you a lot for sharing, using node-loader fixed the same issue for me.

shawnlauzon commented 6 years ago

Thanks @dnichols, I hit the same problem, I ported the same solution over to Nuxt, by modifying nuxt.config.js:

// nuxt.config.js
module.exports = {
  build: {
    extend(config, { isDev, isClient }) {
      // Extend only webpack config for client-bundle
      if (isClient) {
        config.target = "electron-renderer";

        // Required for node-keytar to load
        config.module.rules.push({ test: /\.node$/, loader: "node-loader" });
      }
    },
   ...
}