thom4parisot / crx

A node.js command line app for packing Google Chrome extensions.
https://npmjs.com/crx
MIT License
517 stars 70 forks source link

use crx pack failed #123

Closed Jcanno closed 4 years ago

Jcanno commented 4 years ago
const crx = new ChromeExtension({
  privateKey: fs.readFileSync('./dist.pem')
});

crx.load( path.resolve(__dirname, 'dist') )
   .then(crx => crx.pack())
   .then(crxBuffer => {
     fs.writeFile('myExtension.crx', crxBuffer);
   })
   .catch(err=>{
     console.error( err );
   });

I just copy code of document and delete codebase option, use my correct path, but pack going error, how should I do?

// error
fs.js:141
  throw new ERR_INVALID_CALLBACK(cb);
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
ahwayakchih commented 4 years ago

Example code needs to be updated, because fs.writeFile requires callback now. Try this:

const crx = new ChromeExtension({
  privateKey: fs.readFileSync('./dist.pem')
});

crx.load( path.resolve(__dirname, 'dist') )
   .then(crx => crx.pack())
   .then(crxBuffer => {
     fs.writeFile('myExtension.crx', crxBuffer, err => err ? console.error(err) : console.log('extension file written'));
   })
   .catch(err=>{
     console.error( err );
   });

or something like this:

const crx = new ChromeExtension({
  privateKey: fs.readFileSync('./dist.pem')
});

crx.load( path.resolve(__dirname, 'dist') )
   .then(crx => crx.pack())
   .then(crxBuffer => fs.promises.writeFile('myExtension.crx', crxBuffer))
   .catch(err=>{
     console.error( err );
   });