twit icon indicating copy to clipboard operation
twit copied to clipboard

Webpack Compatibility

Open ariesshrimp opened this issue 8 years ago • 4 comments

It looks like this isn't compatible with Webpack.

Consider:

// index.js
// The minimum required file
const Twit = require('twit')
// OR
import Twit from 'twit'
// webpack.config.js
module.exports = {
  entry: {
    main: './index.js'
  },
  output: {
    filename: 'bundle.js',
    path: __dirname
  },
  target: 'node',
  module: {
    loaders: [
      { test: /\.js$/, loader: 'babel', exclude: /node_modules/ },
      { test: /\.json$/, loader: 'json' }
    ]
  }
}

node node_modules/.bin/webpack && node bundle.js returns:

    module.exports = function() { throw new Error("define cannot be used indirect"); };
                                  ^

Error: define cannot be used indirect
    at Object.module.exports [as define] (/Users/joe/ratticusscript/bundle.js:33865:38)
    at Object.module.exports (/Users/joe/ratticusscript/bundle.js:33615:2)
    at __webpack_require__ (/Users/joe/ratticusscript/bundle.js:20:30)
    at Object.<anonymous> (/Users/joe/ratticusscript/bundle.js:32779:23)
    at __webpack_require__ (/Users/joe/ratticusscript/bundle.js:20:30)
    at Object.<anonymous> (/Users/joe/ratticusscript/bundle.js:32372:15)
    at __webpack_require__ (/Users/joe/ratticusscript/bundle.js:20:30)
    at Object.<anonymous> (/Users/joe/ratticusscript/bundle.js:16366:15)
    at __webpack_require__ (/Users/joe/ratticusscript/bundle.js:20:30)
    at Object.<anonymous> (/Users/joe/ratticusscript/bundle.js:8697:22)
    at __webpack_require__ (/Users/joe/ratticusscript/bundle.js:20:30)
    at Object.hasOwn (/Users/joe/ratticusscript/bundle.js:6423:20)
    at __webpack_require__ (/Users/joe/ratticusscript/bundle.js:20:30)
    at Object.<anonymous> (/Users/joe/ratticusscript/bundle.js:71:16)
    at __webpack_require__ (/Users/joe/ratticusscript/bundle.js:20:30)
    at Object.<anonymous> (/Users/joe/ratticusscript/bundle.js:49:14)

Seems related to this issue over in Webpack: https://github.com/webpack/webpack/issues/138 Something about a dependency on validate.js?

ariesshrimp avatar Sep 24 '16 21:09 ariesshrimp

I'm using this with webpack - maybe it has to do with your config.

hoodsy avatar Oct 21 '16 15:10 hoodsy

@hoodsy can you share a link to your config? still seeing errors in a different project.

ariesshrimp avatar May 27 '17 01:05 ariesshrimp

Try adding this to webpack.config.js

  node: {
    console: false,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }

cogitoergosumsw avatar Jan 18 '18 07:01 cogitoergosumsw

Did you figure this out joe?

darcy-vitacca avatar May 26 '20 03:05 darcy-vitacca