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

Failed to resolve import #248

Open
gaetansenn opened this issue Apr 6, 2023 · 5 comments
Open

Failed to resolve import #248

gaetansenn opened this issue Apr 6, 2023 · 5 comments

Comments

@gaetansenn
Copy link

Environment

node: v16.19.0

Reproduction

git clone https://github.com/gaetansenn/vunix
git checkout bugs/stub-symbol
yarn dev:nuxt-example

Describe the bug

I'm still facing a few problems with the build of my mono-repo project.
The first problem is with the dev build when using the --stub option of the https://github.com/unjs/unbuild
Here is the error when using the command: yarn dev:nuxt-example
The reproduction can be found on the branch: bugs/stub-symbol with yarn dev:nuxt-example command.

nuxt-example:dev:  ERROR  Failed to resolve import "file:///Users/gaetansenn/Development/dewib/librairies/vunix/node_modules/jiti/lib/index.js" from "../../packages/default-preset-tailwind/dist/index.mjs". Does the file exist?
nuxt-example:dev: 
nuxt-example:dev: ✔ Nitro built in 465 ms
nuxt-example:dev: ℹ Vite client warmed up in 2202ms

Additional context

My second problem is that, after updating the code on the branch bugs/stub-symbol, I encountered a problem with the Symbol() export used inside the @vunix/core package. It seems that the Symbol called from https://github.com/gaetansenn/vunix/blob/bugs/stub-symbol/packages/core/src/runtime/utils/config.ts#L175 is not returning the same symbol as the one used in https://github.com/gaetansenn/vunix/blob/bugs/stub-symbol/packages/core/src/runtime/components/elements/button/Button.vue#L66 I have added a comment to the latter version using a fixed string for the provide/inject.

Logs

No response

@johannschopplich
Copy link
Contributor

I'm having the same error in my unlazy pnpm monorepo on macOS.

This is my current solution:

"scripts": {
  "jiti-fix": "find ./dist -type f -exec sed -i '' 's|file://||g' {} \\;",
  "dev": "unbuild --stub && npm run jiti-fix"
},

I can't pin down the issue why the file:/// prefix is added in the Jiti dev build.

@sadeghbarati
Copy link

#438

I tried your solution on macOS too, the error gone from console but in localhost still got the same error

@nekomeowww
Copy link

Weird. I tried "jiti-fix": "find ./dist -type f -exec sed -i '' 's|file://||g' {} \\;",, luckily, the error was resolved for vite, but the error remains in console of localhost:5173 just like what #248 (comment) have mentioned:

Uncaught SyntaxError: The requested module '/@fs/Users/neko/project/node_modules/.pnpm/[email protected]/node_modules/jiti/lib/index.js?v=d951be74' does not provide an export named 'default'

@justin-schroeder
Copy link

I had this issue too and wrote a little unplugin yesterday to fix it in our app by transforming the file:// url to the relative path between the two modules:

https://github.com/justin-schroeder/unplugin-file-url

@czhlin
Copy link

czhlin commented Sep 7, 2024

 hooks: {
    'build:done': async ctx => {
      // https://github.com/unjs/unbuild/issues/248
      if (ctx.options.stub) {
        fglob.sync('./dist/**/*.*js', { onlyFiles: true }).forEach(item => {
          const filePath = path.resolve(__dirname, item);
          fs.readFile(filePath, (err, data) => {
            if (err) {
              return err;
            }
            let str = data.toString();
            str = str.replace(/file:\/\/\/(.+)/g, subStr =>
              path.relative(path.resolve(filePath, '..'), url.fileURLToPath(subStr)).replace(/\\/g, '/')
            );
            fs.writeFile(filePath, str, err => {
              if (err) return err;
            });
          });
        });
      }
    }
  },

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

No branches or pull requests

6 participants