diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index ea9efb8a5..f310b112c 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -1033,7 +1033,13 @@ export class Resolver { if (pkg.packageJSON.exports) { let found = resolveExports(pkg.packageJSON, request.specifier, { browser: true, - conditions: ['default', 'imports'], + /** + * Ideally, these would be exported by vite, but the constant + * that defines client conditions is not exposed to us + * + * See: https://vite.dev/config/shared-options.html#resolve-conditions + */ + conditions: ['import', 'module', 'browser' /*, development | production */, 'default'], }); if (found?.[0]) { return logTransition( diff --git a/packages/vite/src/optimize-deps.ts b/packages/vite/src/optimize-deps.ts index d0ee47ff2..3263191cc 100644 --- a/packages/vite/src/optimize-deps.ts +++ b/packages/vite/src/optimize-deps.ts @@ -10,6 +10,10 @@ export function optimizeDeps(): OptimizeDeps { exclude: ['@embroider/macros'], extensions: ['.hbs', '.gjs', '.gts'], esbuildOptions: { + // When optimizing deps for development, + // always allow the latest featuers + // (such as top level await) + target: 'esnext', plugins: [esBuildResolver()], }, }; diff --git a/tests/scenarios/v2-addon-test.ts b/tests/scenarios/v2-addon-test.ts index f67fe825d..a02466227 100644 --- a/tests/scenarios/v2-addon-test.ts +++ b/tests/scenarios/v2-addon-test.ts @@ -7,6 +7,18 @@ const { module: Qmodule, test } = QUnit; appScenarios .map('v2-addon-basics', project => { + let fakeContentTag = baseV2Addon(); + fakeContentTag.pkg.name = 'fake-content-tag'; + fakeContentTag.pkg.exports = { + browser: './browser.js', + default: './not-browser.js', + }; + fakeContentTag.pkg.files = ['browser.js', 'not-browser.js']; + merge(fakeContentTag.files, { + 'browser.js': `export const value = 'browser'`, + 'not-browser.js': `export const value = 'not browser'`, + }); + let addon = baseV2Addon(); addon.pkg.name = 'v2-addon'; (addon.pkg as any)['ember-addon']['app-js']['./components/example-component.js'] = @@ -34,11 +46,16 @@ appScenarios 'import-from-npm.js': ` export default async function() { let { message } = await import('third-party'); - return message() + let { value } = await import('fake-content-tag'); + + if (value !== 'browser') throw new Error('Incorrect conditions for fake-content-tag'); + + return message(); } `, }); + addon.addDependency(fakeContentTag); addon.addDependency('third-party', { files: { 'index.js': `