Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imports starting with <app-name>/file do not work consistently #1442

Open
x8BitRain opened this issue May 22, 2023 · 3 comments
Open

Imports starting with <app-name>/file do not work consistently #1442

x8BitRain opened this issue May 22, 2023 · 3 comments

Comments

@x8BitRain
Copy link

With embroider 3.0.0 and using Typescript we get the following error on the page when creating imports like import config from 'app-name/config/environment';

Uncaught Error: Could not find module app-name/config/environment.js imported from (require)

Changing them to relative paths like import config from './config/environment'; works fine.

Another example where changing the path just does not work at all is making imports inside the mirage folder like:

import { CONSTANTS } from 'app-name/utils/mock-constants';

These ones never resolve properly.

But these imports worked perfectly fine on the following embroider version.

"@embroider/compat": "2.1.1-unstable.21eae41",
"@embroider/core": "2.1.1-unstable.21eae41",
"@embroider/router": "^2.0.0-unstable.21eae41",
"@embroider/webpack": "2.1.1-unstable.21eae41",

One version newer than that and it breaks.

I can't really provide a repro repo at this time but this is our embroider config:

const embroiderConfig = {
        staticAddonTestSupportTrees: true,
        staticAddonTrees: false,
        staticHelpers: false,
        staticModifiers: false,
        staticComponents: false,
        extraPublicTrees: [webSdk, flatpickrCss],
        skipBabel: [
            {
                package: 'qunit',
            },
            {
                package: 'sinon',
            },
        ],
    };

package.json

{
    "name": "app-name",
    "version": "0.0.0",
    "private": true,
    "license": "MIT",
    "author": "",
    "directories": {
        "doc": "doc",
        "test": "tests"
    },
    "scripts": {
        "start": "ember serve",
        "test": "COVERAGE=true npm-run-all lint \"test:!(serve)\"",
        "test:ember": "COVERAGE=true ember test",
        "test:serve": "npm run lint && COVERAGE=true  ember test --server",
        "release": "semantic-release",
        "prepare": "husky install",
    },
    "devDependencies": {
        "@ember/optional-features": "2.0.0",
        "@ember/render-modifiers": "2.0.4",
        "@ember/test-helpers": "2.6.0",
        "@ember/test-waiters": "3.0.2",
        "@embroider/compat": "3.0.0",
        "@embroider/core": "3.0.0",
        "@embroider/router": "2.1.0",
        "@embroider/webpack": "3.0.0",
        "@glimmer/component": "1.1.2",
        "@glimmer/tracking": "1.1.2",
        "@semantic-release/changelog": "5.0.1",
        "@semantic-release/exec": "5.0.0",
        "@types/ember__application": "4.0.0",
        "@types/ember__array": "4.0.1",
        "@types/ember__component": "4.0.0",
        "@types/ember__controller": "4.0.0",
        "@types/ember__debug": "4.0.1",
        "@types/ember__engine": "4.0.0",
        "@types/ember__error": "4.0.0",
        "@types/ember__object": "4.0.2",
        "@types/ember__polyfills": "4.0.0",
        "@types/ember__routing": "4.0.7",
        "@types/ember__runloop": "4.0.1",
        "@types/ember__service": "4.0.0",
        "@types/ember__string": "3.16.3",
        "@types/ember__template": "4.0.0",
        "@types/ember__test": "3.16.1",
        "@types/ember__test-helpers": "2.0.2",
        "@types/ember__utils": "3.16.2",
        "@types/ember-data": "4.0.0",
        "@types/ember-data__adapter": "4.0.0",
        "@types/ember-data__model": "4.0.0",
        "@types/ember-data__serializer": "4.0.0",
        "@types/ember-data__store": "4.0.0",
        "@types/ember-qunit": "3.4.14",
        "@types/ember-resolver": "5.0.10",
        "@types/file-saver": "2.0.5",
        "@types/htmlbars-inline-precompile": "1.0.1",
        "@types/qunit": "2.11.2",
        "@types/rsvp": "4.0.4",
        "@typescript-eslint/eslint-plugin": "5.0.0",
        "@typescript-eslint/parser": "5.0.0",
        "autoprefixer": "10.4.7",
        "babel-eslint": "10.1.0",
        "broccoli-asset-rev": "3.0.0",
        "conventional-changelog-conventionalcommits": "4.6.1",
        "ember-auto-import": "2.4.2",
        "ember-changeset": "4.1.0",
        "ember-cli": "4.6.0",
        "ember-cli-app-version": "5.0.0",
        "ember-cli-babel": "7.26.11",
        "ember-cli-code-coverage": "2.0.0-beta.4",
        "ember-cli-dependency-checker": "3.3.1",
        "ember-cli-dependency-lint": "2.0.1",
        "ember-cli-deprecation-workflow": "2.1.0",
        "ember-cli-htmlbars": "6.0.1",
        "ember-cli-inject-live-reload": "2.1.0",
        "ember-cli-mirage": "v3.0.0-alpha.3",
        "ember-cli-postcss": "7.1.0",
        "ember-cli-sass": "11.0.1",
        "ember-cli-scss-lint": "2.4.1",
        "ember-cli-sri": "2.1.1",
        "ember-cli-terser": "4.0.2",
        "ember-cli-typescript-blueprints": "3.0.0",
        "ember-click-outside": "4.0.0",
        "ember-concurrency": "2.2.1",
        "ember-concurrency-ts": "0.3.1",
        "ember-data": "4.4.0",
        "ember-data-change-tracker": "0.10.1",
        "ember-export-application-global": "2.0.1",
        "ember-fetch": "8.1.1",
        "ember-in-element-polyfill": "1.0.1",
        "ember-intl": "5.7.2",
        "ember-load-initializers": "2.1.2",
        "ember-maybe-import-regenerator": "1.0.0",
        "ember-modifier": "3.2.7",
        "ember-power-select": "5.0.4",
        "ember-qunit": "5.1.5",
        "ember-resolver": "8.0.3",
        "ember-simple-auth": "4.2.2",
        "ember-source": "4.6.0",
        "ember-svg-jar": "2.3.4",
        "ember-template-lint": "4.4.0",
        "ember-template-lint-plugin-prettier": "^4.1.0",
        "ember-truth-helpers": "3.0.0",
        "eslint": "7.32.0",
        "eslint-config-prettier": "8.5.0",
        "eslint-plugin-ember": "10.6.1",
        "eslint-plugin-node": "11.1.0",
        "eslint-plugin-prettier": "4.0.0",
        "eslint-plugin-qunit": "6.2.0",
        "extract-zip": "2.0.1",
        "faker": "5.5.3",
        "file-saver": "2.0.5",
        "flatpickr": "4.6.9",
        "husky": "8.0.2",
        "lint-staged": "13.1.0",
        "loader.js": "4.7.0",
        "miragejs": "^0.1.47",
        "npm-run-all": "4.1.5",
        "postcss": "8.4.13",
        "prettier": "2.6.1",
        "qunit": "2.18.0",
        "qunit-dom": "2.0.0",
        "sass": "1.43.2",
        "semantic-release": "17.0.7",
        "tracked-built-ins": "3.1.0",
        "typescript": "4.4.4",
        "webpack": "5.73.0"
    },
    "exports": {
        "./*": "./app/*",
        "./mirage/*": "./mirage/*"
    },
    "engines": {
        "node": ">= 14.*"
    },
    "ember": {
        "edition": "octane"
    },
    "ember-addon": {
        "paths": [
            "lib/google-analytics",
            "lib/hubspot"
        ]
    },
    "app-name": {
        "assetTarget": "dist/assets/web-sdk"
    },
    "volta": {
        "node": "16.15.0",
        "npm": "8.11.0",
        "yarn": "1.22.19"
    },
}
@void-mAlex
Copy link
Collaborator

still need to investigate but, maybe a side-effect of #1386

@mansona
Copy link
Member

mansona commented Jun 28, 2023

Hey thanks for the report 🎉

In general import config from 'app-name/config/environment'; is expected to work, but only from app code. You can't do this from any code that is executed in the context of an addon. Could you give more context of where you were trying to require these files from?

You mentioned that you were trying to import constants in your mirage code, but unfortunately Mirage does some funky stuff and includes your mirage folder as addon code during the build. This is a known issue but for now you can try moving the constants you need into the mirage folder and import them from there elsewhere in your app

@x8BitRain
Copy link
Author

Okay, so the mirage folder is treated as an addon and cannot import anything from within the app folder and work properly under embroider?

For example a role.ts model would have export const USER_ROLE = {...}
and in a scenario file in the mirage folder we'd import USER_ROLE that from the user.ts model with
import { USER_ROLE } from 'app-name/models/role';. Stuff like this is what breaks the build. Not the best pattern we do this so we don't have to duplicate a bunch of objects in the test environment when we are using them in both the app and in the tests.

Imports like import config from 'app-name/config/environment'; in app.js don't work properly.

It's just curious that everything built, all tests passed properly on a specific in-dev version of Embroider from a few months back but after that nothing worked anymore. These versions worked fine but we didn't want to ship with an unstable preview 😄

"@embroider/compat": "2.1.1-unstable.21eae41",
"@embroider/core": "2.1.1-unstable.21eae41",
"@embroider/router": "^2.0.0-unstable.21eae41",
"@embroider/webpack": "2.1.1-unstable.21eae41",

I will try to create a repo where this is reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants