Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require is not a function #133

Closed
kevupton opened this issue Jul 28, 2017 · 7 comments
Closed

require is not a function #133

kevupton opened this issue Jul 28, 2017 · 7 comments

Comments

@kevupton
Copy link

kevupton commented Jul 28, 2017

I am receiving these errors when I deploy to serverless.
I am using webpack and typescript with faunadb.
Whenever I import faunadb and get query I get these errors.

WARNING in ./~/formidable/lib/incoming_form.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/incoming_form.js 1:43-50

WARNING in ./~/formidable/lib/json_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/json_parser.js 1:43-50

WARNING in ./~/formidable/lib/file.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/file.js 1:43-50

WARNING in ./~/formidable/lib/querystring_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/querystring_parser.js 1:43-50

And when i run get require is not defined. So serverless then defaults to an internal server error.

The script goes as follows

import { db } from '../db/client';
import * as faunadb from 'faunadb';
import { Application } from '../../system/app';

const q = faunadb.query; // <--- this is the line that breaks it. If i comment out it works.
@erickpintor
Copy link
Contributor

Hi @kevupton. Unfortunately, I'm not able to simulate this error. It seems to be a known issue with formidable, a sub-dependency of the JS driver. Would you mind trying their recommended workaround and reporting back, please?

@kevupton
Copy link
Author

kevupton commented Aug 3, 2017

Hey @erickpintor somethign super weird is happening. I am going to list out all the details as I have no idea what is going on.

So I added the fix they recommended: new webpack.DefinePlugin({ "global.GENTLY": false }) and this worked when I was only using webpack. If I use webpack and serverless together it seems to break as above.

However webpack on its on requires me to remove the '' from the

  resolve: {
    extensions: ['.ts', '.js', '.tsx', '.jsx', '']
  },

otherwise it will error out, saying invalid configuration object webpack resolve extension empty string

However when I remove that and run webpack with serverless. I receive the following error. Entry module not found: Error: Cannot resolve 'file' or 'directory'

So I add the '' back into the extensions and then that fixes the above error message, however will then break on the original error messages.

So the conclusion is it seems to only break when I combine serverless and webpack. Which is unusal, as the webpack versions are the same, when I run it without serverless and with serverless.

My webpack configuration object is as follows:

module.exports = {
  entry: './handler.ts',
  target: 'node',
  module: {
    loaders: [
      { test: /\.ts(x?)$/, loader: 'ts-loader' },
      { test: /\.json$/, loader: 'json-loader' },
    ]
  },
  resolve: {
    extensions: ['.ts', '.js', '.tsx', '.jsx']
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: 'handler.js'
  },
  plugins: [
    new webpack.IgnorePlugin(/vertx/),
    new webpack.DefinePlugin({ "global.GENTLY": false })
  ]
};

If you can point me in a direction I would be very much appreciated. This has me stumped for a few days now.

@kevupton
Copy link
Author

kevupton commented Aug 4, 2017

So I have solved the problem, and it seemed to be caused by an outdated version of the serverless-webpack plugin. RIP
Just had to update that plugin and then it worked

@erickpintor
Copy link
Contributor

I'm glad you've found the solution. Thanks for replying back to us.
I'm going to close this for now but, feel free to open new issues if need any help.

@iamtekeste
Copy link

I am facing this issue and since I am using Netlify Dev, I don't think there is a way I can modify my webpack.config.json.
Is there any other way I can get over this obstacle, I am really eager to use FaunaDB but I am unable to to do anything so far.

@danieltodonnell
Copy link
Contributor

@iamtekeste We will talk about this in our standup tomorrow and see what we can work out about it?

@iamtekeste
Copy link

For what it is worth I have found a workaround for it, turns out Netlify Dev/Netlify Lambda accepts a config param and you can pass it a custom webpack.config.js file.
More info here netlify/netlify-faunadb-example#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants