commercetools / merchant-center-application-kit

Tools and components for developing Merchant Center Customizations đź› 
https://docs.commercetools.com/merchant-center-customizations
MIT License
67 stars 27 forks source link

Issues with pegjs errors #2722

Closed kmahadevan01 closed 2 years ago

kmahadevan01 commented 2 years ago

We ran the build with the old version of "@commercetools-frontend/mc-scripts: 17.0.0" and the build was successful. But, while running the test cases, though we have fixed react-intl errors, the rest of the errors shown in the test cases are pegjs errors. PFA for reference. While debugging, we found pegjs, and their dependencies are removed from CT. Our current code is using pegjs for parsing. To address jest errors, we have upgraded/downgraded the version of jest and its dependencies. But, still, we are getting the same errors in all the scenarios. Since it is deprecated, could you please let us know the alternative library we could use for parsing Error: `Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.`
image image
emmenko commented 2 years ago

Hi @kmahadevan01 ,

Yes the pegjs dependency has been removed from the appkit packages. Internally we still use it and I can share the setup that you can use to make it work (even with all the latest appkit dependencies).

One question though out of curiosity: what is your use case for using pegjs?


Internally we are using "pegjs": "0.10.0" and "pegjs-loader": "0.5.6" (you need it for Webpack) as dependencies in your package.json.

Next you need to configure the Webpack loader.

Create a webpack.config.dev.js:

const {
  createWebpackConfigForDevelopment,
} = require('@commercetools-frontend/mc-scripts/webpack');

const config = createWebpackConfigForDevelopment();

config.module.rules = config.module.rules.concat({
  test: /\.pegjs$/,
  use: [require.resolve('pegjs-loader')],
});

module.exports = config;

And a webpack.config.prod.js:

const {
  createWebpackConfigForProduction,
} = require('@commercetools-frontend/mc-scripts/webpack');

const config = createWebpackConfigForProduction();

config.module.rules = config.module.rules.concat({
  test: /\.pegjs$/,
  use: [require.resolve('pegjs-loader')],
});

module.exports = config;

In your Jest config you then need to configure the transformer to load the .pegjs files:

const path = require('path');
const basePreset = require('@commercetools-frontend/jest-preset-mc-app');

const jestPreset = {
  ...basePreset,
  transform: {
    ...basePreset.transform,
    '^.+\\.pegjs$': path.resolve(__dirname, './jest.pegjs.transform.js'),
  },
};

module.exports = jestPreset;

And finally you need to create a jest.pegjs.transform.js:

// This transformer is shamelessly extracted from
// https://github.com/danwang/pegjs-jest
// The original library is incompatible with current Jest API
// and looks abandoned.

const crypto = require('crypto');
const peg = require('pegjs');

const getCacheKey = (fileData, filePath) =>
  crypto.createHash('md5').update(fileData).digest('hex');

const process = (sourceText, sourcePath, options) =>
  `module.exports = ${peg.generate(sourceText, { output: 'source' })}`;

module.exports = {
  getCacheKey,
  process,
};
kmahadevan01 commented 2 years ago

Hello @emmenko, Thanks for your response. We are using pegjs to transform cart predicate into form values. @smurugan Can you please check on the data shared by @emmenko and see if this helps to resolve our issue?

pandiarajan-nu commented 2 years ago

@emmenko we are using enzyme in the jest config.

const jestPreset = require('@commercetools-frontend/jest-preset-mc-app');
const applyJestPresetWithEnzyme = require('@commercetools-frontend/jest-preset-mc-app/enzyme/apply-jest-preset-with-enzyme');

module.exports = {
  ...applyJestPresetWithEnzyme({
    enzymeAdapterVersion: 17,
    jestPreset,
  }),
};
emmenko commented 2 years ago

@pandiarajan-nu Sure, you can do it this way then:

const path = require('path');
const basePreset = require('@commercetools-frontend/jest-preset-mc-app');
const applyJestPresetWithEnzyme = require('@commercetools-frontend/jest-preset-mc-app/enzyme/apply-jest-preset-with-enzyme');

const jestPreset = {
  ...basePreset,
  transform: {
    ...basePreset.transform,
    '^.+\\.pegjs$': path.resolve(__dirname, './jest.pegjs.transform.js'),
  },
};

module.exports = {
  ...applyJestPresetWithEnzyme({
    enzymeAdapterVersion: 17,
    jestPreset,
  }),
};
selvam-murugan-nu commented 2 years ago

@emmenko Thanks for the quick reply and now pegs issue got resolved and we are getting follwing error. i tried to run yarn build and yarn test and observed following errors with the below version of mc-scripts. "@commercetools-frontend/mc-scripts": "21.9.0",

yarn build

Error: MomentLocalesPlugin: Moment.js doesn’t include a few locales you specified: en-in, en-sg. Check the plugin’s localesToKeep option. You can see the full list of locales that Moment.js includes in node_modules/moment/locale/. If you would like unsupported locales to be ignored, please use the ignoreInvalidLocales option.

File Path: express-solution-enablement/packages/ensemble-custom-application/node_modules/@commercetools-frontend/mc-scripts/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js:34 throw err; ^ Error: Failed to compile

I just analysed the mc-script package and came to know moment.js used by mc-script and few of the locales are missing.

yarn test

FAIL test src/components/ensemble-list/ensemble-list.spec.js ● Test suite failed to run Jest encountered an unexpected token Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax. Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration. By default "node_modules" folder is ignored by transformers. Here's what you can do: • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it. • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config. • If you need a custom transformation specify a "transform" option in your config. • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option. You'll find more details and examples of these config options in the docs: https://jestjs.io/docs/configuration For information about custom transformations, see: https://jestjs.io/docs/code-transformation Error Details: express-solution-enablement/packages/ensemble-custom-application/node_modules/@babel/runtime-corejs3/helpers/esm/defineProperty.js:1 ({"Object.":function(module,exports,require,dirname,filename,jest){import _Object$defineProperty from "../../core-js/object/define-property"; SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14) at Object. (node_modules/@express-labs/mc-custom-applications-core/index.js:1:1010)

enzyme config for spec.js files are missing (ensemble-list.spec.js ) all of the spec.js file test cases are failing.

Please check both cases and provide us your solutions

Thanks & Regards, Selvam M

emmenko commented 2 years ago

MomentLocalesPlugin: Moment.js doesn’t include a few locales you specified: en-in, en-sg.

Can you share which moment version have you installed / are using?

enzyme config for spec.js files are missing (ensemble-list.spec.js ) all of the spec.js file test cases are failing.

Can you share your jest.test.config.js file?

selvam-murugan-nu commented 2 years ago

@emmenko in our package.json we dont have moment.js dependency’s by mc-script its installed.

"moment-locales-webpack-plugin": "1.2.0",
image

here is my jest.test.config.js file

const path = require('path');
const basePreset = require('@commercetools-frontend/jest-preset-mc-app');
const applyJestPresetWithEnzyme = require('@commercetools-frontend/jest-preset-mc-app/enzyme/apply-jest-preset-with-enzyme');

const jestPreset = {
  ...basePreset,
  transform: {
    ...basePreset.transform,
    '^.+\\.pegjs$': path.resolve(__dirname, './jest.pegjs.transform.js'),
  },
};

module.exports = {
  ...applyJestPresetWithEnzyme({
    enzymeAdapterVersion: 17,
    jestPreset,
  }),
};
emmenko commented 2 years ago

in our package.json we dont have moment.js dependency’s by mc-script its installed.

Sorry my bad I wasn't clear. I meant to check with yarn why moment to see which versions are installed.

here is my jest.test.config.js file

The example I shared was mostly related to the additional pegjs setup. How was the jest config before that?

selvam-murugan-nu commented 2 years ago

@emmenko Yarn why moment result below i have attached.

yarn why v1.22.10
[1/4] 🤔  Why do we have the module "moment"...?
[2/4] đźšš  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "ensemble-custom-application#moment@2.24.0"
info Reasons this module exists
   - "_project_#ensemble-custom-application" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "3.48MB"
info Disk size with unique dependencies: "3.48MB"
info Disk size with transitive dependencies: "3.48MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#moment-timezone#moment@2.29.1"
info Reasons this module exists
   - "_project_#ensemble-custom-application#moment-timezone" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.14MB"
info Disk size with unique dependencies: "5.14MB"
info Disk size with transitive dependencies: "5.14MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/i18n#moment@2.29.3"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#i18n" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.16MB"
info Disk size with unique dependencies: "5.16MB"
info Disk size with transitive dependencies: "5.16MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/application-shell#moment@2.29.4"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-shell" depends on it
   - Hoisted from "_project_#ensemble-custom-application#@commercetools-frontend#application-shell#@commercetools-frontend#i18n#moment"
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.16MB"
info Disk size with unique dependencies: "5.16MB"
info Disk size with transitive dependencies: "5.16MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/application-shell-connectors#moment@2.29.1"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-shell-connectors#moment-timezone" depends on it
   - Hoisted from "_project_#ensemble-custom-application#@commercetools-frontend#application-shell-connectors#moment-timezone#moment"
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.14MB"
info Disk size with unique dependencies: "5.14MB"
info Disk size with transitive dependencies: "5.14MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/application-shell#moment-timezone#moment@2.29.1"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-shell#moment-timezone" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.14MB"
info Disk size with unique dependencies: "5.14MB"
info Disk size with transitive dependencies: "5.14MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/application-components#moment@2.29.4"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-components#@commercetools-frontend#i18n" depends on it
   - Hoisted from "_project_#ensemble-custom-application#@commercetools-frontend#application-components#@commercetools-frontend#i18n#moment"
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.16MB"
info Disk size with unique dependencies: "5.16MB"
info Disk size with transitive dependencies: "5.16MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/l10n#moment@2.29.4"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-components#@commercetools-frontend#l10n" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.16MB"
info Disk size with unique dependencies: "5.16MB"
info Disk size with transitive dependencies: "5.16MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/react-notifications#moment@2.29.4"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-shell#@commercetools-frontend#react-notifications" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.16MB"
info Disk size with unique dependencies: "5.16MB"
info Disk size with transitive dependencies: "5.16MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/l10n#moment-timezone#moment@2.29.1"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-components#@commercetools-frontend#l10n#moment-timezone" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.14MB"
info Disk size with unique dependencies: "5.14MB"
info Disk size with transitive dependencies: "5.14MB"
info Number of shared dependencies: 0
=> Found "ensemble-custom-application#@commercetools-frontend/react-notifications#moment-timezone#moment@2.29.1"
info Reasons this module exists
   - "_project_#ensemble-custom-application#@commercetools-frontend#application-shell#@commercetools-frontend#react-notifications#moment-timezone" depends on it
   - in the nohoist list ["/_project_/ensemble-custom-application/**","/_project_/ensemble-custom-application/@express-labs/mc-custom-applications-core/*","/_project_/**/mocha","/_project_/**/mocha/**"]
info Disk size without dependencies: "5.14MB"
info Disk size with unique dependencies: "5.14MB"
info Disk size with transitive dependencies: "5.14MB"
info Number of shared dependencies: 0
✨  Done in 0.91s.
pandiarajan-nu commented 2 years ago

@emmenko This is previous jest.test.config.js

const preset = require('@commercetools-frontend/jest-preset-mc-app');

module.exports = {
  ...preset,
  transform: {
    ...preset.transform,
    '^.+\\.pegjs$': 'pegjs-jest',
  },
};
emmenko commented 2 years ago

Regarding moment, it looks like you're using an old version here. That might likely be the issue:

image
emmenko commented 2 years ago

As for the jest issue, hard to say without having the full picture.

SyntaxError: Cannot use import statement outside a module

What things are you importing in the ensemble-list.spec.js file?

PS: as much as we would like to help, it's hard for us to "guess" without having more context/info to look at. At the end of the day, many of these "issues" are tooling and setup related and not really specific to Custom Applications. Often times it's about dependencies and conflicting versions, which is something that you would face in general in any project.

selvam-murugan-nu commented 2 years ago

PS: as much as we would like to help, it's hard for us to "guess" without having more context/info to look at. At the end of the day, many of these "issues" are tooling and setup related and not really specific to Custom Applications. Often times it's about dependencies and conflicting versions, which is something that you would face in general in any project.

Yeah we can able to resolve the issues if anything outside the CT packages but here all the errors are depends upon the CT packages. mc-script earlier version all test cases passed successfully including spec.js. latest version its not supporting for who are still using enzyme.Its not about setup something from our side.since we are not having our own test scripts.

I pointed here few of the issues what we found and reported to CT. These issues we dont have any soultion in the upgrade documentation.

Ex: Pegjs support depricated from CT packges without any notice and there is no documentation for who are still using pegjs. Enzyme adapter also depricated from CT packages there is no documentation provided how to use enzyme adapter who are all still using ezyme test cases.we went to each repo's readme file and then identified the deprecated libraries and then configured the changes.

I am attaching here one of our sepc file.

import React from 'react'; import { shallow } from 'enzyme'; import faker from 'faker'; import times from 'lodash/times'; import { FormattedMessage } from 'react-intl'; import { getMutation, setMutation, setQuery, useQuery, } from '@commercetools-frontend/application-shell'; import { mockShowNotification } from '@commercetools-frontend/actions-global'; import * as AppContext from '@commercetools-frontend/application-shell-connectors'; import { GRAPHQL_TARGETS } from '@commercetools-frontend/constants'; import { generateEnsemble, generateSubmittedFormValues } from '../../test-util'; import UpdateEnsemble from './update-ensemble.graphql'; import EditEnsemble from './edit-ensemble'; import EnsembleForm from '../ensemble-form'; import GetCartDiscountCodes from './get-discount-codes.graphql'; import messages from './messages';

pandiarajan-nu commented 2 years ago

After upgrading moment js and with "@commercetools-frontend/mc-scripts": "17.0.0"(as 21.9.0 throws build error),

we are getting the same errors as yesterday related to @commercetools-frontend/jest-preset-mc-app and jest configs ` Console

console.error
   WARN  @commercetools-frontend/jest-preset-mc-app: console.error calls should not be used in tests. 
   Warning: Failed %s type: %s%s prop Invalid prop `horizontalConstraint` of value `l` supplied to `FieldLabel`, expected one of [3,4,5,6,7,8,9,10,11,12,13,14,15,16,"scale","auto"]. 
      at FieldLabel (/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@commercetools-uikit/field-label/dist/commercetools-uikit-field-label.cjs.dev.js:41:13)

`

`Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.`

`({"Object.":function(module,exports,require,dirname,filename,jest){import _Object$defineProperty from "../../core-js/object/define-property"; ^^^^^^

SyntaxError: Cannot use import statement outside a module

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
  at Object.<anonymous> (node_modules/@express-labs/mc-custom-applications-core/index.js:1:1010)`
emmenko commented 2 years ago

Pegjs support depricated from CT packges without any notice and there is no documentation for who are still using pegjs.

The removal of pegjs was properly documented as a breaking change, since version v11

image

And the linked PR provided guidance on how to migrate: #402

Enzyme adapter also depricated from CT packages there is no documentation provided how to use enzyme adapter who are all still using ezyme test cases.

This one was also properly documented and marked as a breaking change, since version v20.

https://github.com/commercetools/merchant-center-application-kit/blob/main/packages/jest-preset-mc-app/CHANGELOG.md#2000


Again, it's a bit hard to help with little info and no insight of the repository. Internally in our teams we also use both pegjs and enzyme and we don't have issues with them.

I can suggest the following steps:

Hopefully this helps you further.

selvam-murugan-nu commented 2 years ago

Pegjs support depricated from CT packges without any notice and there is no documentation for who are still using pegjs.

The removal of pegjs was properly documented as a breaking change, since version v11

Release notes Mentioned it's breaking change for V11 but we can able to run the build "@commercetools-frontend/mc-scripts": "17.0.0", without any exrta pegjs configuration, which currently we have in our prodction. You have shared the change log of that library but we were adviced to follow the following documentation to upgrade . https://docs.commercetools.com/custom-applications/releases The above documentation doesn't have anything related to pegjs removal and apply-jest-preset-with-enzyme adaptor. It's very difficult to refer each repo and make investigation on the release notes.

We have checked the sample repo's given by Nick and seems like which are using @testing-library/react package for test cases since we are using JestPresetWithEnzyme https://github.com/commercetools/merchant-center-application-kit/tree/main/application-templates/starter

so we need some sample latest package.json with using latest mc-scripts along with enzyme test case configuration.which gets build successfully including test cases.

Note: We have investigated the error and noticed the issue is from babel library which gets installed as part of mc-scripts and attched screenshot FYI.

image
pandiarajan-nu commented 2 years ago

we have upgraded the babel version in mc-custom-application-core and with @commercetools-frontend/mc-scripts:21.9.0 we are getting the following error from mc-scripts package.

Screenshot 2022-07-26 at 10 45 30 AM Screenshot 2022-07-26 at 10 46 46 AM
emmenko commented 2 years ago

What react version do you have installed?

pandiarajan-nu commented 2 years ago

"react": "17.0.2", "react-dom": "17.0.2",

emmenko commented 2 years ago

Have you tried googling for these kind of errors?

I just did and it hints to some issue related to @emotion/react. Can you check which versions of these packages do you have installed?

yarn why @emotion/react
pandiarajan-nu commented 2 years ago

Yes. we have installed @emotion/react: 11.9.0 already. do we need to add any additional dependency packages for this?

here is the result of yarn why @emotion/react

yarn why v1.22.10 [1/4] 🤔 Why do we have the module "@emotion/react"...? [2/4] 🚚 Initialising dependency graph... [3/4] 🔍 Finding dependency... [4/4] 🚡 Calculating file sizes... => Found "@emotion/react@11.9.0" info Has been hoisted to "@emotion/react" info Reasons this module exists

pandiarajan-nu commented 2 years ago
Screenshot 2022-07-29 at 1 47 43 AM

Tried these @emotion/react related solutions from google. Still no luck. Getting the following errors.

Attempted import error: 'useInsertionEffect' is not exported from 'react' (imported as 't').

/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@commercetools-frontend/mc-scripts/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js:34 throw err; ^

Error: Failed to compile at _callee2$ (/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@commercetools-frontend/mc-scripts/dist/build-9b6d7eee.cjs.dev.js:212:19) at tryCatch (/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@babel/runtime-corejs3/helpers/regeneratorRuntime.js:105:17) at Generator._invoke (/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@babel/runtime-corejs3/helpers/regeneratorRuntime.js:85:24) at Generator.throw (/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@babel/runtime-corejs3/helpers/regeneratorRuntime.js:139:21) at asyncGeneratorStep (/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@babel/runtime-corejs3/helpers/asyncToGenerator.js:5:24) at _throw (/Users/vajhu/Public/express-labs/express-solution-enablement/packages/ensemble-custom-application/node_modules/@babel/runtime-corejs3/helpers/asyncToGenerator.js:31:9) at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5) error Command failed with exit code 1.

pandiarajan-nu commented 2 years ago

https://github.com/commercetools/merchant-center-application-kit/tree/main/application-templates/starter

We tried this above sample repo provided by CT with latest packages. With Node v14.19.1, while running build we got the following error related to mc-scripts.

Screenshot 2022-07-29 at 2 24 44 AM
emmenko commented 2 years ago

@pandiarajan-nu It looks like you have been cloning/forking the application-kit repo. Please don't do that.

To install a new starter template, please follow the instructions in the Getting started documentation, using the @commercetools-frontend/create-mc-app CLI.

Thanks.

pandiarajan-nu commented 2 years ago

we did the steps you provided, we installed using mc-app. with that sample package, we added our libraries and tested ensemble-custom-application. But we are getting the same error.

Attempted import error: 'useInsertionEffect' is not exported from 'react' (imported as 't').

We tried google solutions also emotion and react version changes also. no luck

selvam-murugan-nu commented 2 years ago

@emmenko Any updares on this ? we requested package.json file with enzyme test cases. can you please share ? thanks

emmenko commented 2 years ago

we did the steps you provided, we installed using mc-app. with that sample package, we added our libraries and tested ensemble-custom-application. But we are getting the same error.

I would suggest to do the work step-by-step.

Also, besides the tests failing, is the app working as expected when you start the development server or build the production bundles?

selvam-murugan-nu commented 2 years ago

@emmenko mc-custom-application-core is another package we are using and when we use mc-scripts to build that package we cant able to build it. this package also provided by commerce tools. We are using babel. "@babel/core": "7.18.10", "babel-plugin-import-graphql": "^2.8.1", "babel-plugin-react-intl": "^8.2.25", "babel-plugin-transform-rename-import": "^2.3.0", Does any recommended version for mc-custom-application-core ? We can able to successfully build the mc-custom-application-core.

emmenko commented 2 years ago

The "mc-custom-applications-core" is an old package shared by the Professional Service team that hasn't been maintained for over 2 years.

Very likely, many of the issues you are encountering are caused by that package, as it contains very old dependency versions that are just causing all sorts of conflicts.

I would strongly recommend to remove that package. I'm sure many of the things implemented in that package can be replaced with other components from UI Kit and Application Kit (which is generally recommended).

pandiarajan-nu commented 2 years ago

Hi. we have removed mc-custom-application-core from ensemble and imported the components. build was success. we got test cases failed.

FAIL src/components/entry-point/entry-point.spec.js ● rendering › should render examples-starter route

Method “props” is meant to be run on 1 node. 0 found instead.

  12 |
  13 |   it('should render examples-starter route', () => {
> 14 |     expect(wrapper.find(Route).prop('path')).toEqual(
     |                                ^
  15 |       `/:projectKey/${ROOT_PATH}`
  16 |     );
  17 |   });

  at ShallowWrapper.single (node_modules/enzyme/src/ShallowWrapper.js:1652:13)
  at ShallowWrapper.props (node_modules/enzyme/src/ShallowWrapper.js:1175:17)
  at ShallowWrapper.prop (node_modules/enzyme/src/ShallowWrapper.js:1311:17)
  at Object.<anonymous> (src/components/entry-point/entry-point.spec.js:14:32)

Snapshot Summary › 1 snapshot failed from 1 test suite. Inspect your code changes or run yarn test -u to update them.

Test Suites: 2 failed, 1 skipped, 19 passed, 21 of 22 total Tests: 7 failed, 19 skipped, 166 passed, 192 total Snapshots: 1 failed, 1 passed, 2 total Time: 19.509 s

emmenko commented 2 years ago

Hi. we have removed mc-custom-application-core from ensemble and imported the components. build was success.

That's good news! 🙌

About the failing test entry-point.spec.js, I would actually remove it, we found that it's not really useful for that component to test it. If there are other tests that are failing, and you don't know or have the time to fix them, I would consider to temporarily disable them (at least until the migration is completed).

The important thing is that the application works both in development and production. Can you confirm that this is the case?

For testing, in the long term I would suggest to move away from Enzyme and use RTL (React Testing Library). You can read more about our recommendations here: https://docs.commercetools.com/custom-applications/development/testing

pandiarajan-nu commented 2 years ago
Screenshot 2022-08-10 at 10 32 32 PM

Hi. Thanks for the suggestion. build and test cases success in the local. We have started the service and it redirected to mc login page. when we tried to login, we are getting login error. same credential working in mc-app.

selvam-murugan-nu commented 2 years ago

@emmenko below is the redirected url when we start from local. https://mc.us-central1.gcp.commercetools.com/login/authorize?reason=unauthorized&client_id=__local%3Aensemble-manager&response_type=id_token&scope=openid%20project_key%3Astardust-stage-1%20view%3Aview_types%2Cview_products%20view%3Aview_cart_discounts%20view%3Aview_discount_codes%20manage%3Amanage_types%2Cmanage_products%20manage%3Amanage_discount_codes%20manage%3Amanage_cart_discounts&state=52a750ca-e96d-41c8-bf0b-925f7e65260a&nonce=52a750ca-e96d-41c8-bf0b-925f7e65260a

selvam-murugan-nu commented 2 years ago

@emmenko I can able to logged in i am getting below error after i logged in can you please check ?

image

Here is our custom-config.json file.

`{ "name": "Ensembles Management", "entryPointUriPath": "ensemble-manager", "cloudIdentifier": "gcp-us", "env": { "production": { "url": "https://${env:ENSEMBLE_CUSTOM_APP_DOMAIN}", "cdnUrl": "https://${env:ENSEMBLE_CUSTOM_APP_DOMAIN}", "applicationId":"application id" }, "development": { "initialProjectKey":"stardust-stage-1" } }, "oAuthScopes": { "view": ["view_products", "view_cart_discounts","view_discount_codes"], "manage": ["manage_products","manage_discount_codes","manage_cart_discounts"] }, "icon": "${path:@commercetools-frontend/assets/application-icons/pricetag.svg}", "featureToggle": null, "mainMenuLink": { "defaultLabel": "Ensemble Manager", "labelAllLocales": [ { "locale": "en", "value": "Ensemble Manager" }, { "locale": "de", "value": "Ensemble Manager" }, { "locale": "es", "value": "Ensemble Manager" } ], "permissions": ["ViewDiscountCodes", "ViewCartDiscounts"] }, "submenuLinks": [] }

` Route.js file we updated the canViewProducts condition to below condition.

image

Below is our constant file.

image

Kindly check and let us know if anything we are missing to run the application in local. Thank you.

emmenko commented 2 years ago

Here is our custom-config.json file.

Looks good more or less. Just a few points:

Route.js file we updated the canViewProducts condition to below condition.

You can remove that because it's implicitly done by the <ApplicationShell> (checking for the View permission). See documentation: https://docs.commercetools.com/custom-applications/api-reference/commercetools-frontend-application-shell#usage

Below is our constant file.

That looks fine yes.

I can able to logged in i am getting below error after i logged in can you please check ?

This does not seem an error coming from our APIs or tools. It seems it's something your application renders. Did you check that and the logic around that to understand what the issue might be?

kmahadevan01 commented 2 years ago

We got past the errors. However in stage, when we are trying to edit the promotion, we are getting the following error

image

Could you please help us with this?

nspeet commented 2 years ago

Are the custom types setup properly from terraform?

leninexpress commented 2 years ago

@pandiarajan-nu can you please share the terraform file here to review by CT team.

pandiarajan-nu commented 2 years ago

Generally any changes terraform will be taken care by our devops. our file is given below.

ensemble-custom-types.txt

emmenko commented 2 years ago

Hi everyone, it seems that most of the original issues have been solved (e.g. pegjs, etc). Therefore, I'll close this issue as it's already been going off topic a bit.

If you have another specific issue with Custom Applications or the migration, feel free to open a new issue (or a discussion if you only have questions).

If you have issues with the logic and data of the app itself (terraform, etc.) I'm afraid we can't help you much with that and I suggest to maybe open a support ticket so that other teams with more context of your app can try helping you.

Thanks

kmahadevan01 commented 2 years ago

We were able to fix the edit issue locally. We will progress with deployment and reach out here in case of any issues.