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

clearCache with null chunk #143

Closed
svengau opened this issue Apr 17, 2019 · 3 comments
Closed

clearCache with null chunk #143

svengau opened this issue Apr 17, 2019 · 3 comments
Labels

Comments

@svengau
Copy link
Contributor

svengau commented Apr 17, 2019

Hi,

I've recently added a new lambda function with mainly serverless-http, apollo-server-express, graphql-modules and got this error when starting, preventing to run the server:

➜  yarn lambda-serve
yarn run v1.15.2
$ NODE_ENV=development netlify-lambda -c ./netlify.webpack.functions.js serve lambda-src
netlify-lambda: Starting server
Hash: e5ff9126f80c7609c6e2
Version: webpack 4.29.6
Time: 7100ms
Built at: 04/18/2019 6:49:38 AM
     Asset       Size   Chunks             Chunk Names
      0.js   8.29 MiB        0  [emitted]
      1.js   19.5 KiB        1  [emitted]
      2.js  673 bytes        2  [emitted]
graphql.js   9.84 MiB  graphql  [emitted]  graphql
Entrypoint graphql = graphql.js
[...]
path.js:39
    throw new ERR_INVALID_ARG_TYPE('path', 'string', path);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.join (path.js:1157:7)
    at Object.clearCache (/workspace/cfa/pronostics-lyonnais/node_modules/netlify-lambda/lib/serve.js:183:25)

I use netlify-lambda v1.4.5 but I've met this issue in the previous version too.

The error is thrown by clearCache, because 3 chunks have an undefined name, and come from this piece of code:

stats.compilation.chunks.forEach(function(chunk) {
        server.clearCache(chunk.name);
});

Those chunks are created in the lambda function with the id instead (0.js, 1.js, ...) and seem to be related to typescript (but I don't use typescript at all in my source code), and graphql-related libraries like graphql-import.

Also, just in case, here is my webpack custom config:

module.exports = {
  mode: 'development',
  plugins: [new webpack.DefinePlugin({ 'global.GENTLY': false })],
  resolve: {
    alias: {
      lib: path.resolve(__dirname, 'lambda-src/lib/'),
      '@client': path.resolve(__dirname, 'src/'),
    },
    // modules: ['node_modules', path.resolve(__dirname, 'lambda-src')],
  },
  module: {
    rules: [
      {
        test: /\.mjs$/,
        type: 'javascript/auto',
        include: /node_modules/,
        use: [],
      },
    ],
  },
};

From my understanding we should fallback to chunk.id if chunk.name is undefined, when clearing the cache.

@svengau
Copy link
Contributor Author

svengau commented Apr 17, 2019

I use this PR on my local, and it fixes the issue.

@swyxio
Copy link
Contributor

swyxio commented Apr 17, 2019

thanks, i dont have a strong opinion on this right now and would love if someone else also thought this through before we merge

@stale
Copy link

stale bot commented Jun 16, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 16, 2019
@swyxio swyxio closed this as completed Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants