Skip to content

Do not silently ignore package.json in zeit deployment #1540

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

Merged
merged 1 commit into from
Feb 15, 2019

Conversation

oroce
Copy link
Contributor

@oroce oroce commented Feb 14, 2019

What kind of change does this PR introduce?
Fix

What is the current behavior?

If you omit the files entry in your now.json then the deployment works without any issues but if you customize the now.files and you happen to have package.json in that list, it will be ignored from the deployment. If the package.json is omitted then zeit won't install the required dependencies.

Example configuration:

now.json

{
  "version": 2,
  "files": [
      "index.js",
      "package.json"
   ],
   "builds": [{
      "src": "index.js",
      "use": "@now/node"
    }]
}

package.json

{
  "dependencies": {
       "express": "4.16.4"
   }
}

index.js

require('express');

The deployment of a sandbox with the configuration above will be successful but when you are trying to open your deployment it'll crash with an error of 500. (MODULE_NOT_FOUND)

What is the new behavior?

If the user add package.json to the now.files it'll be included.

Checklist:

I found this issue while I was building a Pusher authentication server using zeit for a sample vue chat app. I had to define the now.files since the sandbox has lots of files (config, static, build, etc) which should be deployed to zeit (and cannot be due to some zeit errors). For now, I moved the server to a different sandbox and deployed from there.

If you omit the `files` entry in your `now.json` then the deployment works without any issues but if you customize the `now.files` and you happen to have `package.json` in that list, it will be ignored from the deployment. If the package.json is omitted then zeit won't install the required dependencies.

Example configuration:

now.json
```
{
  "version": 2,
  "files": [
      "index.js",
      "package.json"
   ],
   "builds": [{
      "src": "index.js",
      "use": "@now/node"
    }]
}
```

package.json
```
{
  "dependencies": {
       "express": "4.16.4"
   }
}
```

index.js
```
require('express');
```

The deployment of a sandbox with the configuration above will be successful but when you are trying to open your deployment it'll crash with an error of 500. (`MODULE_NOT_FOUND`)

I found this issue while I was building a Pusher authentication server using zeit for a [sample vue chat app](https://codesandbox.io/s/9z1prn05pr).  I had to define the `now.files` since the sandbox has lots of files (config, static, build, etc) which should be deployed to zeit (and cannot be due to some zeit errors). For now, I moved the server to a different sandbox and deployed from [there](https://codesandbox.io/s/j4v80y7wzw).
@SaraVieira SaraVieira merged commit af43adc into codesandbox:master Feb 15, 2019
@SaraVieira
Copy link
Contributor

Thank you for fixing this!

@ValentinFunk
Copy link

Has this perhaps caused an issue? For me I always get an error with duplicate files when uploading to Zeit:

{"error":{"code":"invalid_files","message":"One or more file definitions contain errors in them","errors":[{"reason":"duplicated_file_path","path":"package.json"}]}}

There are two package.json in the request when uploading with this now.json:

{
  "version": 2,
  "name": "my-react-app",
  "builds": [
    {
      "src": "package.json",
      "use": "@now/static-build",
      "config": {
        "distDir": "build"
      }
    }
  ],
  "routes": [
    {
      "src": "^/static/(.*)",
      "headers": {
        "cache-control": "s-maxage=31536000,immutable"
      },
      "dest": "/static/$1"
    },
    {
      "src": "^/favicon.ico",
      "dest": "/favicon.ico"
    },
    {
      "src": "^/asset-manifest.json",
      "dest": "/asset-manifest.json"
    },
    {
      "src": "^/manifest.json",
      "dest": "/manifest.json"
    },
    {
      "src": "^/precache-manifest.(.*)",
      "dest": "/precache-manifest.$1"
    },
    {
      "src": "^/service-worker.js",
      "headers": {
        "cache-control": "s-maxage=0"
      },
      "dest": "/service-worker.js"
    },
    {
      "src": "^/(.*)",
      "headers": {
        "cache-control": "s-maxage=0"
      },
      "dest": "/index.html"
    }
  ]
}

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

Successfully merging this pull request may close these issues.

3 participants