vite-aliases icon indicating copy to clipboard operation
vite-aliases copied to clipboard

0.97 - Can't use vite-aliases

Open tsanyqudsi opened this issue 1 year ago • 15 comments

ERROR: [plugin: externalize-deps] Failed to resolve entry for package "vite-aliases". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." entry in "vite-aliases" package

I think you need to change package.json and how tsup compile tho. I'll send you a PR

tsanyqudsi avatar Oct 18 '22 16:10 tsanyqudsi

@Subwaytime I will give it to your judgement to close this issue since the more I dig up, I starting to believe that this is an issue with vite-plugin-solid.

The main issue with SolidJS in vite using vite-aliases are :

  • Aliases are not generating in config.resolve.alias
Generator {
  options: {
    dir: 'src',
    prefix: '@',
    deep: true,
    depth: 1,
    createGlobalAlias: true,
    createLog: false,
    logPath: 'src/logs',
    adjustDuplicates: false,
    useAbsolute: false,
    useConfig: true,
    useIndexes: true,
    useTypescript: true,
    root: '***Omitted***'
  },
  fullPath: '***Omitted***',
  aliases: [],
  directories: Set(0) {},
  paths: {},
  searched: false,
  servermode: 'serve'
}
  • ERR_PACKAGE_PATH_NOT_EXPORTED ( current workaround is to update the package.json ).
Couldn't find package.json for vite-aliases Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in ***Omitted***\node_modules\vite-aliases\package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:589:7)
    at resolveExports (node:internal/modules/cjs/loader:522:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:562:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:971:27)
    at Function.resolve (node:internal/modules/cjs/helpers:109:19)
    at***Omitted***node_modules/vite-plugin-solid/dist/esm/index.mjs:53:35
    at Array.map (<anonymous>)
    at getSolidDeps (***Omitted***node_modules/vite-plugin-solid/dist/esm/index.mjs:48:21) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Your example is working well so I figures it's because of another vite plugins. I haven't check with react but I will later.

I'm using Windows 10 btw, haven't test it on Linux.

tsanyqudsi avatar Oct 19 '22 04:10 tsanyqudsi

Ill have a look! Thanks for the report :)

Subwaytime avatar Oct 19 '22 15:10 Subwaytime

@Subwaytime thanks bro, tbh vite-aliases helping me big time for years before vite 3 came and ruin everything.

And thanks to your plugin, I had an idea to build yet-another-front-end starter kit using solidjs, will sponsor you next month.

tsanyqudsi avatar Oct 19 '22 17:10 tsanyqudsi

Same here

ViteJS version - ^3.1.8

Error Stack trace
X [ERROR] [plugin externalize-deps] Failed to resolve entry for package "vite-aliases". The package may have incorrect main/module/exports specified in its package.json: No known conditions 
for "." entry in "vite-aliases" package

  node_modules/esbuild/lib/main.js:1327:27:
    1327 │         let result = await callback({
         ╵                            ^

  at packageEntryFailure (file:///C:/Jivy/exberry/app/trading-ui/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:34841:11)
  at resolvePackageEntry (file:///C:/Jivy/exberry/app/trading-ui/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:34836:9)
  at tryNodeResolve (file:///C:/Jivy/exberry/app/trading-ui/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:34584:20)
  at file:///C:/Jivy/exberry/app/trading-ui/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:63472:44
  at requestCallbacks.on-resolve (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1327:28)
  at handleRequest (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:697:19)
  at handleIncomingPacket (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:719:7)
  at Socket.readFromStdout (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:647:7)
  at Socket.emit (node:events:513:28)
  at addChunk (node:internal/streams/readable:315:12)

This error came from the "onResolve" callback registered here:

  node_modules/esbuild/lib/main.js:1251:20:
    1251 │       let promise = setup({
         ╵                     ^

  at setup (file:///C:/Jivy/exberry/app/trading-ui/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:63465:27)
  at handlePlugins (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1251:21)
  at buildOrServeImpl (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:942:5)
  at Object.buildOrServe (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:750:5)
  at C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:2085:17
  at new Promise (<anonymous>)
  at Object.build (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:2084:14)
  at build (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1931:51)
  at bundleConfigFile (file:///C:/Jivy/exberry/app/trading-ui/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:63432:26)

The plugin "externalize-deps" was triggered by this import

  vite.config.ts:3:28:
    3 │ import { ViteAliases } from 'vite-aliases';
      ╵                             ~~~~~~~~~~~~~~

failed to load config from C:\Jivy\exberry\app\trading-ui\vite.config.ts
error when starting dev server:
Error: Build failed with 1 error:
node_modules/esbuild/lib/main.js:1327:27: ERROR: [plugin: externalize-deps] Failed to resolve entry for package "vite-aliases". The package may have incorrect main/module/exports specified i
n its package.json: No known conditions for "." entry in "vite-aliases" package
  at failureErrorWithLog (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1566:15)
  at C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1024:28
  at runOnEndCallbacks (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1438:61)
  at buildResponseToResult (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1022:7)
  at C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:1134:14
  at responseCallbacks.<computed> (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:671:9)
  at handleIncomingPacket (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:726:9)
  at Socket.readFromStdout (C:\Jivy\exberry\app\trading-ui\node_modules\esbuild\lib\main.js:647:7)
  at Socket.emit (node:events:513:28)
  at addChunk (node:internal/streams/readable:315:12)

nichita-pasecinic avatar Oct 20 '22 06:10 nichita-pasecinic

Having this error too

monarcode avatar Oct 20 '22 07:10 monarcode

@nichita-pasecinic these look like two different errors, so ill fix them seperately! Thanks for the report

Subwaytime avatar Oct 20 '22 07:10 Subwaytime

@Subwaytime Actually this might have anything to do with no type: module on their package.json as I mentioned on my PR back then.

@monarcode , @nichita-pasecinic do you have those ? Because it will give those errors on your app when you don't have those as mentioned in https://github.com/Subwaytime/vite-aliases/pull/44#issuecomment-1282892495

tsanyqudsi avatar Oct 20 '22 08:10 tsanyqudsi

I will add this also to the readme file, as installation instructions. The ESM move should have been more clear! Sorry about that

Subwaytime avatar Oct 20 '22 08:10 Subwaytime

@Subwaytime Actually this might have anything to do with no type: module on their package.json as I mentioned on my PR back then.

@monarcode , @nichita-pasecinic do you have those ? Because it will give those errors on your app when you don't have those as mentioned in #44 (comment)

i removed type: module when installed vite-aliases at first... this is how i get it to work normally..is that the issue?

monarcode avatar Oct 20 '22 08:10 monarcode

@monarcode most probably, yes.

tsanyqudsi avatar Oct 20 '22 09:10 tsanyqudsi

@Subwaytime , I don't have type defined in my package.json

nichita-pasecinic avatar Oct 20 '22 10:10 nichita-pasecinic

@Subwaytime , I don't have type defined in my package.json

try adding them, You use Vite 3 ? Because I don't think vite-aliases pasca 0.95 support Vite 2 anymore.

tsanyqudsi avatar Oct 20 '22 11:10 tsanyqudsi

adding "type":"mofule" fixed the issue for me 👍🏽

monarcode avatar Oct 20 '22 12:10 monarcode

@nichita-pasecinic i deleted the comment, as thats not part of the conversation. Vite-aliases is meant for bigger projects where having distinct aliases per folder is important for managing and organizing the code base. Having one alias is totally fine but it also just turns your aliases into an entire path.

Subwaytime avatar Oct 20 '22 13:10 Subwaytime

@Subwaytime you're the boss here 😄

nichita-pasecinic avatar Oct 20 '22 19:10 nichita-pasecinic

yarn run v1.22.19
$ vite
✘ [ERROR] [plugin externalize-deps] Failed to resolve entry for package "vite-aliases". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." entry in "vite-aliases" package

    node_modules/vite/node_modules/esbuild/lib/main.js:1327:27:
      1327 │         let result = await callback({
           ╵                            ^

This error came from the "onResolve" callback registered here:

    node_modules/vite/node_modules/esbuild/lib/main.js:1251:20:
      1251 │       let promise = setup({
           ╵                     ^

  The plugin "externalize-deps" was triggered by this import

    vite.config.ts:17:28:
      17 │ import { ViteAliases } from 'vite-aliases';
         ╵                             ~~~~~~~~~~~~~~


           ```

thisVioletHydra avatar Oct 28 '22 19:10 thisVioletHydra

@thisVioletHydra This has already been reported upwards, you need to add "type":"module" to your package.json, as the latest version moved entirely to ESM.

Subwaytime avatar Oct 29 '22 13:10 Subwaytime

its good solution but my postcss crashed if i set type: module 🙃

thisVioletHydra avatar Oct 29 '22 13:10 thisVioletHydra

@thisVioletHydra do you have the error report for when your postcss crashed ?

Most probably it has nothing to do with vite-aliases but the implemenation of vite ( https://github.com/vitejs/vite/issues/10192 )

update : Don't use postcss.config.ts since it won't work with vite and esm. maybe you could use postcss.config.mjs instead

tsanyqudsi avatar Oct 30 '22 03:10 tsanyqudsi

I will close this issue since it's need to be more specific and the discussion is widening.

tsanyqudsi avatar Nov 03 '22 01:11 tsanyqudsi

@thisVioletHydra This has already been reported upwards, you need to add "type":"module" to your package.json, as the latest version moved entirely to ESM.

yes,it's useful

mvslan avatar Mar 11 '23 14:03 mvslan