primefaces / primevue-nuxt-module

MIT License
70 stars 11 forks source link

Resolution path is wrong #44

Closed RebeccaStevens closed 5 months ago

RebeccaStevens commented 6 months ago

Components are registered with filePaths like "primevue/checkbox" instead of an absolute path.

This results in build errors like

 ERROR  Could not resolve entry module "primevue/checkbox".

Rollup seems to be trying to resolve '/path/to/project/primevue/checkbox' (as unresolvedId is set to this) instead of '/path/to/project/node_modules/primevue/checkbox'/'/path/to/project/node_modules/.pnpm/primevue@3.46.0_vue@3.4.15/node_modules/primevue/checkbox/'.

related: https://github.com/primefaces/primevue/issues/5009

Potential Fix

Changing this line:

https://github.com/primefaces/primevue-nuxt-module/blob/cb2d6c5f567637ddcd17526a068a45e12b04a9fe/src/register.ts#L146

const nodeModulesResolver = createResolver("node_modules");
const resolvePath = (resolveOptions: ResolvePathOptions) => nodeModulesResolver.resolve(Utils.object.getPath(moduleOptions.resolvePath, resolveOptions));

This now gets Rollup to resolve '/path/to/project/node_modules/primevue/checkbox' which works, but '/path/to/project/node_modules/.pnpm/primevue@3.46.0_vue@3.4.15/node_modules/primevue/checkbox/' would be the idea path (when using pnpm and those versions).

mertsincan commented 5 months ago

Hi,

Interesting! I wrote this structure following the nuxt-module specification. I think you can use resolvePath method for such case.

primevue: {
        options: {
            ripple: true
        },
        layerOrder: 'primevue',
        resolvePath: function ({ as, from, type }) {
           // you can update the path
            return ...;
        }
    },

Best Regards,

RebeccaStevens commented 5 months ago

I tried the following:

import { createRequire } from "node:module";
const { resolve } = createRequire(import.meta.url);

// ...

primevue: {
  resolvePath({ from }) {
    return resolve(from);
  },
}

And everything seems to resolve correctly, until I get to the prerenderer step in the build. This is an improvement as before it was erroring out at the start of the build.

The error I'm now getting looks like this:

 ERROR  [nuxt] [request error] [unhandled] [500] The requested module 'file:///path/tp/project/node_modules/.pnpm/vue@3.4.15_typescript@5.3.3/node_modules/vue/index.mjs' does not provide an export named 'default'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)  
  at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)  
  at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)  
  at async ./.nuxt/prerender/chunks/renderer.mjs:143:24

Errors prerendering:
  ├─ / (143ms)                                                                                                                
  │ └── Error: [500] 

 ERROR  Exiting due to prerender errors.

Any idea why this error could be occurring?

RebeccaStevens commented 5 months ago

For now this works for me:

import path from "node:path";

// ...

primevue: {
  resolvePath({ from }) {
    return path.resolve(`node_modules/${from}`);
  },
}

with shamefully-hoist=true in .npmrc