Cannot read property 'fsPath' of undefined

Hi! :slight_smile:

I’m trying to deploy my company’s site and I’m getting this error:

TypeError: Cannot read property 'fsPath' of undefined
2020-02-07T12:33:50.534Z      at Object.build (/zeit/b027f802d99b8095/.build-utils/.builder/node_modules/@frontity/now/dist/index.js:95:49)
2020-02-07T12:33:50.534Z      at async buildStep (/var/task/sandbox-worker.js:20292:20)
2020-02-07T12:33:50.534Z      at async mainSub (/var/task/sandbox-worker.js:20047:9)
2020-02-07T12:33:50.534Z      at async main (/var/task/sandbox-worker.js:19975:5)

Here is my now.json file:

{
  "version": 2,
  "builds": [
    {
      "src": "api/*.js",
      "use": "@now/node"
    },
    {
      "src": "package.json",
      "use": "@frontity/now"
    }
  ],
  "routes": [
    {
      "src": "/certificacao-digital",
      "status": 308,
      "headers": { "Location": "/certificados-digitais/" }
    },
    {
      "src": "/framework",
      "status": 308,
      "headers": { "Location": "/bry-framework/" }
    },
    {
      "src": "/certificado-de-atributos",
      "status": 308,
      "headers": { "Location": "/bry-atributos/" }
    },
    { "src": "/api/(.*)", "methods": ["GET"], "status": 404 },
    {
      "src": "/api/(.*)",
      "headers": { "cache-control": "no-cache" },
      "dest": "/api/$1.js"
    },
    {
      "src": "/static/(.*)",
      "headers": {
        "cache-control": "public,max-age=31536000,immutable"
      },
      "dest": "/static/$1"
    },
    { "src": "/favicon.ico", "dest": "favicon.ico" },
    {
      "src": "($|/.*)",
      "headers": {
        "cache-control": "s-maxage=1,stale-while-revalidate"
      },
      "dest": "/server.js"
    }
  ],
  "build": {
    "env": {
      "SSH_PRIVATE_KEY": "@gitlab-ssh-key-react-ui-components"
    }
  }
}

I think that this error was generated after I inserted an build env variable. :thinking:

Here is my gitlab-ci.yml:

 image: node
before_script:
  - "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
  - eval $(ssh-agent -s)
  - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
stages:
  - setup
  - test
  - deploy
setup:
  stage: setup
  script:
    - npm install
    - npm run build
test:
  stage: test
  script: npm test
deploy_staging:
  stage: deploy
  script:
    - npm i -g now --silent
    - npm install
    - npm run build
    - now -e NODE_ENV=staging --token=${NOW_TOKEN}
    - now alias site2020.bry.now.sh --token=${NOW_TOKEN}
  environment:
    name: staging
    url: https://site2020.bry.now.sh
  only:
    - master
deploy_prod:
  stage: deploy
  script:
    - npm i -g now --silent
    - npm install
    - npm run build
    - now -e NODE_ENV=production --token=${NOW_TOKEN}
    - now alias site2020-puce-one.now.sh --token=${NOW_TOKEN}
  environment:
    name: production
    url: https://site2020-puce-one.now.sh
  only:
    - master

UPDATE:

I successful deployed changing my now.json file to:

{
  "version": 2,
  "builds": [
    {
      "src": "api/*.js",
      "use": "@now/node"
    },
    {
      "src": "build/static/**/*",
      "use": "@now/static"
    },
    {
      "src": "favicon.ico",
      "use": "@now/static"
    },
    {
      "src": "build/server.js",
      "use": "@now/node"
    },

    {
      "src": "package.json",
      "use": "@now/node-server"
    }
  ],
  "routes": [
    {
      "src": "/certificacao-digital",
      "status": 308,
      "headers": { "Location": "/certificados-digitais/" }
    },
    {
      "src": "/framework",
      "status": 308,
      "headers": { "Location": "/bry-framework/" }
    },
    {
      "src": "/certificado-de-atributos",
      "status": 308,
      "headers": { "Location": "/bry-atributos/" }
    },
    { "src": "/api/(.*)", "methods": ["GET"], "status": 404 },
    {
      "src": "/api/(.*)",
      "headers": { "cache-control": "no-cache" },
      "dest": "/api/$1.js"
    },
    {
      "src": "/static/(.*)",
      "headers": {
        "cache-control": "public,max-age=31536000,immutable"
      },
      "dest": "/build/static/$1"
    },
    { "src": "/favicon.ico", "dest": "favicon.ico" },
    {
      "src": "($|/.*)",
      "headers": {
        "cache-control": "s-maxage=1,stale-while-revalidate"
      },
      "dest": "/build/server.js"
    }
  ],
  "build": {
    "env": {
      "SSH_PRIVATE_KEY": "@gitlab-ssh-key-react-ui-components"
    }
  }
}

Is it good?

Hi @luisherranz! I suppose that I cant use build variables inside my now.json. Maybe @frontity/now are deleting this command. :thinking:

My gitlab-ci.yml are showing the following message:

Now CLI 17.0.3
- Setting up project
Error! You defined 1 build that did not match any source files (please ensure they are NOT defined in .nowignore):
- {"src":"build/server.js","use":"@now/node"}

If I deploy with npm run build && now --prod works perfectly.

Any one can see the problem in my now.json or gitlab-ci?

It looks like the TypeError: Cannot read property 'fsPath' of undefined error is generated by Webpack failing to create the server.js file.

If you run npx frontity dev -p in that exact commit, does it generate a server.js file?

Yes, but my build directory is in .gitignore. .nowignore also is inherited from gitignore too.

If you use @frontity/now the npx frontity build will happen in the cloud.

But the Cannot read property 'fsPath' of undefined errors means something went wrong while building the server.js file. Probably an error in Webpack bundling.

Looks like frontity/now arent working with the new now cli (17.0.3). :thinking:

I think that the problem is in frontity/now dependencies. Now updated their @now/build-utils. One solution is freeze package @now/build-utils version in 0.9.4 and @now/node-bridge in 1.2.3. What do you think @luisherranz? Can I freeze this version in my package.json? Using resolutions or dependencies?

Maybe change the caret for tilde for prevent breaking changes

I’ve just created a new Frontity project with npx frontity create, then added this now.json file:

{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@frontity/now"
    }
  ]
}

and finally deploy to now using Now CLI 17.0.3 and it worked fine.

I’m not sure where you error is coming from but you can keep using npm run build && now --prod if that works for you :+1:

:slight_smile: Thanks @luisherranz. I dont know what is happening. I changed my now.json because I have a serveless function in api directory. The problem with my solution is that my “build” directory is in .gitignore. So the build isn’t generated in the master branch.

@luisherranz Only folder analyze is generated with this pipeline:

deploy_staging:
  stage: deploy
  script:
    - npm i -g now@16.7.3 --silent
    - rm ./package-lock.json
    - npm install
    - npm run build
    - cd build
    - ls

The result of ls is just the analyse folder only. :thinking:

Let’s continue here: https://github.com/frontity/now-builder/issues/21

:point_up_2: please start with a clean repo using npx frontity create and add the necessary code to make now stop working. Then share the reproducible repo in the issue and we’ll fix the problem.

1 Like