Deploiment failed when trying to deploy the SPA on symfony cloud

$ /app/node_modules/.bin/encore prod
    W: /app/node_modules/pkg-up/index.js:4
    W: module.exports = async ({cwd} = {}) => findUp('package.json', {cwd});
    W:                        ^
    W: 
    W: SyntaxError: Unexpected token (
    W:     at createScript (vm.js:56:10)
    W:     at Object.runInThisContext (vm.js:97:10)
    W:     at Module._compile (module.js:549:28)
    W:     at Object.Module._extensions..js (module.js:586:10)
    W:     at Module.load (module.js:494:32)
    W:     at tryModuleLoad (module.js:453:12)
    W:     at Function.Module._load (module.js:445:3)
    W:     at Module.require (module.js:504:17)
    W:     at require (internal/module.js:20:19)
    W:     at Object.<anonymous> (/app/node_modules/@symfony/webpack-encore/lib/config/parse-runtime.js:13:15)
    W: error Command failed with exit code 1.

My symfony cloud configuration

name: admin

type: php:7.4
size: S
disk: 256

build:
  flavor: none

dependencies:
  nodejs:
    yarn: "1.22.4"

web:
  commands:
    start: sleep
  locations:
    "/":
      root: "public"
      index:
        - "index.html"
      scripts: false
      expires: 10m

hooks:
  build: |
    set -x -e

    curl -s https://get.symfony.com/cloud/configurator | (>&2 bash)
    yarn-install
    npm rebuild node-sass
    yarn encore prod


my package.json


{
  "name": "admin",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@babel/core": "^7.12.7",
    "@babel/preset-env": "^7.12.7",
    "@symfony/webpack-encore": "^0.31.0",
    "babel-preset-preact": "^2.0.0",
    "html-webpack-plugin": "^4.5.0",
    "preact": "^10.5.7"
  }
}

webpack config


const Encore = require('@symfony/webpack-encore');
const HtmlWebpackPlugin = require('html-webpack-plugin');

Encore
    .setOutputPath('public/')
    .setPublicPath('/')
    .cleanupOutputBeforeBuild()
    .addEntry('app', './src/app.js')
    .enablePreactPreset()
    .enableSingleRuntimeChunk()
    .addPlugin(new HtmlWebpackPlugin({ template: 'src/index.ejs',
        alwaysWriteToDisk: true }))
;

module.exports = Encore.getWebpackConfig();

and my app


import {h, render} from 'preact';

function App() {
    return (
        <div>
        Hello Friends!
    </div>
) }
render(<App />, document.getElementById('app'));

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *