mainmatter / ember-cookies

Cookies abstraction for Ember.js that works both in the browser as well as with Fastboot on the server
MIT License
115 stars 46 forks source link

Trouble using with Embroider app #979

Open tsmalls93 opened 4 days ago

tsmalls93 commented 4 days ago

I have a V2 addon that uses ember-simple-auth. When I try to use the addon in an Embroider app, it fails to start with the following error:

webpack 5.94.0 compiled with 1 error in 2406 ms
Build Error (PackagerRunner) in ../../../../node_modules/.pnpm/ember-customer-auth@1.3.0_@babel+core@7.25.2_@ember+test-helpers@3.3.1_@babel+core@7.25.2_@gl_zlshd7pwbijf4cnbfuif3z53ji/node_modules/ember-customer-auth/dist/routes/application.js

Module not found: Error: ember-customer-auth is trying to import from ember-cookies but that is not one of its explicit dependencies

I have ember-cookies installed as a dependency in my V2 addon, so I am not sure why this error is being thrown. I am using pnpm link if that helps.

BobrImperator commented 4 days ago

Could you share the package.json of your ember-customer-auth addon?

tsmalls93 commented 4 days ago

Sure. I tried putting ember-cookies in dependencies and peerDependencies. Both had the same result.


{
  "name": "ember-customer-auth",
  "version": "1.4.0",
  "description": "The default blueprint for Embroider v2 addons.",
  "keywords": [
    "ember-addon"
  ],
  "repository": "",
  "license": "MIT",
  "author": "",
  "exports": {
    ".": {
      "types": "./declarations/index.d.ts",
      "default": "./dist/index.js"
    },
    "./*": {
      "types": "./declarations/*.d.ts",
      "default": "./dist/*.js"
    },
    "./addon-main.js": "./addon-main.cjs"
  },
  "typesVersions": {
    "*": {
      "*": [
        "declarations/*"
      ]
    }
  },
  "files": [
    "addon-main.cjs",
    "declarations",
    "dist"
  ],
  "scripts": {
    "build": "concurrently 'pnpm:build:*'",
    "build:js": "rollup --config",
    "build:types": "glint --declaration",
    "lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'",
    "lint:fix": "concurrently 'pnpm:lint:*:fix' --names 'fix:'",
    "lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
    "lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
    "lint:js": "eslint . --cache",
    "lint:js:fix": "eslint . --fix",
    "lint:types": "glint",
    "prepack": "concurrently 'pnpm:build:*'",
    "start": "concurrently 'pnpm:start:*'",
    "start:js": "rollup --config --watch --no-watch.clearScreen",
    "start:types": "glint --declaration --watch",
    "test": "echo 'A v2 addon does not have tests, run tests in test-app'"
  },
  "dependencies": {
    "@embroider/addon-shim": "^1.8.7",
    "decorator-transforms": "^2.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.24.4",
    "@babel/plugin-transform-typescript": "^7.24.4",
    "@babel/runtime": "^7.24.4",
    "@embroider/addon-dev": "^4.3.1",
    "@glimmer/tracking": "^1.1.2",
    "@glint/core": "^1.4.0",
    "@glint/environment-ember-loose": "^1.4.0",
    "@glint/environment-ember-template-imports": "^1.4.0",
    "@glint/template": "^1.4.0",
    "@rollup/plugin-babel": "^6.0.4",
    "@tsconfig/ember": "^3.0.6",
    "@types/ember": "^4.0.10",
    "@types/ember-data": "^4.4.16",
    "@types/ember-data__model": "^4.0.5",
    "@types/ember-data__store": "^4.0.7",
    "@types/ember__application": "^4.0.10",
    "@types/ember__array": "^4.0.9",
    "@types/ember__component": "^4.0.21",
    "@types/ember__controller": "^4.0.11",
    "@types/ember__debug": "^4.0.7",
    "@types/ember__destroyable": "^4.0.4",
    "@types/ember__engine": "^4.0.10",
    "@types/ember__error": "^4.0.5",
    "@types/ember__helper": "^4.0.5",
    "@types/ember__modifier": "^4.0.8",
    "@types/ember__object": "^4.0.11",
    "@types/ember__owner": "^4.0.8",
    "@types/ember__polyfills": "^4.0.5",
    "@types/ember__routing": "^4.0.19",
    "@types/ember__runloop": "^4.0.8",
    "@types/ember__service": "^4.0.8",
    "@types/ember__string": "^3.16.3",
    "@types/ember__template": "^4.0.5",
    "@types/ember__test": "^4.0.5",
    "@types/ember__utils": "^4.0.6",
    "@typescript-eslint/eslint-plugin": "^7.7.1",
    "@typescript-eslint/parser": "^7.7.1",
    "babel-plugin-ember-template-compilation": "^2.2.5",
    "concurrently": "^8.2.2",
    "ember-concurrency": "^4.0.2",
    "ember-inflector": "^5.0.1",
    "ember-template-lint": "^6.0.0",
    "eslint": "^8.56.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-ember": "^12.0.2",
    "eslint-plugin-import": "^2.29.1",
    "eslint-plugin-n": "^17.3.1",
    "eslint-plugin-prettier": "^5.1.3",
    "prettier": "^3.2.5",
    "prettier-plugin-ember-template-tag": "^2.0.2",
    "rollup": "^4.16.4",
    "rollup-plugin-copy": "^3.5.0",
    "typescript": "^5.4.5"
  },
  "peerDependencies": {
    "@ember-data/model": "^3.12.0 || ^4.0.0 || ^5.0.0",
    "@ember-data/store": "^3.12.0 || ^4.0.0 || ^5.0.0",
    "ember-concurrency": "^4.0.2",
    "ember-cookies": "^1.1.2",
    "ember-simple-auth": "^6.1.0",
    "ember-simple-auth-oidc": "^6.0.1",
    "webpack": "^5.0.0"
  },
  "publishConfig": {
    "registry": "https://nexus.kub.org/repository/npm-hosted/"
  },
  "ember": {
    "edition": "octane"
  },
  "ember-addon": {
    "version": 2,
    "type": "addon",
    "main": "addon-main.cjs",
    "app-js": {
      "./adapters/authenticated.js": "./dist/_app_/adapters/authenticated.js",
      "./authenticators/oidc.js": "./dist/_app_/authenticators/oidc.js",
      "./models/application-settings.js": "./dist/_app_/models/application-settings.js",
      "./models/user.js": "./dist/_app_/models/user.js",
      "./routes/application.js": "./dist/_app_/routes/application.js",
      "./routes/oidc-authentication.js": "./dist/_app_/routes/oidc-authentication.js",
      "./services/session.js": "./dist/_app_/services/session.js"
    }
  }
}
BobrImperator commented 4 days ago

If that's the current setup, then you might need to make sure that ember-cookies is also installed in the main app. We'd need a reproduction for this, the package.json looks fine.

Interestingly ember-simple-auth does work which has a very similar setup, unless it's not actually imported and you only use the service?

tsmalls93 commented 4 days ago

Yeah. it is a weird issue. I have determined it only happens when I use pnpm link to symlink the addon locally. Once I publish the addon, everything works fine. It also works for the test-app within the addon monorepo.

For ember-simple-auth I had to leave it in peerDependencies. When I put it in dependencies I would get the "Some V1 ember addons are resolving as incorrect peer dependencies." error because of a conflict with @ember/test-helpers. I do not import anything directly from ember-simple-auth directly, but I am overriding a lot in ember-simple-auth-oidc which in turn overrides ember-simple-auth.