Issue #3917Opened November 2, 2021by denny991 reactions

BUG: Compilation Error with Typescript

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Crome 95

Reproducible demo link

none

Describe the bug

How to reproduce the bug?

  1. Add ts config file
{
  "compileOnSave": false,
  "compilerOptions": {
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "baseUrl": "./",
    "outDir": "./target/generated-typescript",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "Node",
    "importHelpers": true,
    "target": "es2017",
    "module": "es2020",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "uuid-random": [
        "../node_modules/uuid-random"
      ],
      "chroma-js": [
        "../node_modules/chroma-js"
      ],
      "faker/locale/en": [
        "../node_modules/faker/locale/en"
      ],
      "moment": [
        "../node_modules/moment"
      ],
      "validator": [
        "../node_modules/validator"
      ],
      "object-hash": [
        "../node_modules/object-hash"
      ]
    }
  },
  "angularCompilerOptions": {
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true
  }
}
  1. Add grapes as dependency
  2. Import Grapes via import * as grapesjs from 'grapesjs'; and @import "~grapesjs/src/styles/scss/main.scss";
  3. Build your project
  4. Get the error
./node_modules/backbone/backbone.js - Error: Module not found: Error: Can't resolve 'jquery' in 'C:\Users\denny\IdeaProjects\WSPone-Platform\frontend\node_modules\backbone'

./node_modules/grapesjs/dist/grapes.min.js - Error: Module not found: Error: Can't resolve 'jquery' in 'C:\Users\denny\IdeaProjects\WSPone-Platform\frontend\node_modules\grapesjs\dist'

What is the expected behavior?

Should build like version .27

What is the current behavior?

So we've recently updated to grapes v17.28. With this particular version we get the error message when building our angular project. It is correct, that we don't have jquery as dependency. But for some reason backbone is requiring it now. The backbone version is still the same as with .27.

As soon as we revert our version to .27 it works totally fine.

The problematic code is

// Next for Node.js or CommonJS. jQuery may not be needed as a module.
} else if (typeof exports !== 'undefined') {
  var _ = require('underscore'), $;
  try { $ = require('jquery'); } catch (e) {}
  factory(root, exports, _, $);

I saw that this project now has a tsconfig file, so it is compiling differently now? This might cause the issue

Code of Conduct

  • I agree to follow this project's Code of Conduct

Answers (2)

artfNovember 3, 20211 reactions

Hi Denny, thanks for the report. I'm closing this in favor of #3902 as it should be related (even if the error is different). Please try the new version and let me know if it fixes the issue.

marcosvnmeloNovember 2, 20210 reactions

I'm working on a React + Typescript project and i'm having this same error on .28 version

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.