GrapesJS / preset-webpage

GrapesJS Plugin Webpage Preset
http://grapesjs.com/demo.html
BSD 3-Clause "New" or "Revised" License
335 stars 291 forks source link

ERROR TypeError: r is not a function while using in PROD #51

Closed eugenio165 closed 2 years ago

eugenio165 commented 3 years ago

Hi! Thanks for the awesome package! It is very useful!

This is related to https://github.com/artf/grapesjs/issues/2658

I am using grapejs with this preset in Angular 7, while i use in development (ng serve) it works fine. But once i build the project, i get this error in the console: ERROR TypeError: r is not a function. It is caused by this package, not by grapesjs itself. I've traced down the error to the source code and it refers to this: image which refers to line 14 in the source code of src/commands/index.js: https://github.com/artf/grapesjs-preset-webpage/blob/3e5a9e12998c9a32b6f1199953084163678e6c17/src/commands/index.js#L12-L16

In this context, r is openImport and as the error states, is not a function. Keep in mind this happens only when i build in prod, so heres my config for angular:

"configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }

Thanks in advance!

MudassarSandhu commented 3 years ago

@eugenio165 Have you solved yet? @artf Any idea why this is happening? I am also facing this issue.

Screenshot 2020-10-26 at 12 38 35 PM Screenshot 2020-10-26 at 12 38 55 PM
eugenio165 commented 3 years ago

@MudassarSandhu Yes, unfortunately i had to disable aot and buildOptimizer on my prod build... If you find a better solution, update me please, thanks

MudassarSandhu commented 3 years ago

Yeah, i did find a solution which fixed my error. How are you importing and initializing the grapesjs-preset-webpage plugin? Use the old method like

import grapesjs from 'grapesjs';
import 'grapesjs-preset-webpage';

And in the initialization of builder

plugins: ['grapesjs-preset-webpage'],
      pluginsOpts: {
        'gjs-preset-webpage': {
        },
      }
}

Add the grapesjs script and plugin script in angular json file in scripts tag like this But order matters if you have any other script in the scripts tag

"scripts": [
    "./node_modules/grapesjs/dist/grapes.min.js",
    "./node_modules/grapesjs-preset-webpage/dist/grapesjs-preset-webpage.min.js",
]
eugenio165 commented 3 years ago

I see... so you can build with prod configurations like that? You didnt have to use my fix (disable AOT and Optimization)?

My implementation is exactly like yours, but my grapesjs scripts aren't the first in the array in the angular json file. I'm too busy currently to go back and try to play around with the project i used this on, but once i have time i'll go check if placing the grapesjs scrips first in the array allows me to build with AOT and Optimization.

MudassarSandhu commented 3 years ago

@eugenio165 yeah i can build with prod configurations. In my project's anular.json file, grapesjs is not the first. I have imported other scripts but i showed you that as an example.

eugenio165 commented 3 years ago

@MudassarSandhu Just to be clear, i can build with prod configurations, but i'll get the error i stated in this issue. When i build without AOT and BuildOptimizer, this error doesnt occur. My implementation is EXACTLY like yours, the only thing that could differ is the order of the scripts array, and maybe the order of the imports in the file i use grapesjs in.

When you build in prod, does grapesjs work correctly? Thanks mate

artf commented 2 years ago

For now, I'm closing this as I can't reproduce it, but if you believe the issue is still there, please create a reproducible demo.