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

fix: compile error following upgrade.md's vite to mix guide #231

Merged
merged 5 commits into from
Jul 6, 2023

Conversation

AshboDev
Copy link
Contributor

Include fix for postcss.config.js when compiling assets

When a user follows the guide in upgrade.md to revert back to mix from vite, and then tries to compile they will most likely get an error, this pull request fixes that.

Include fix for postcss.config.js when compiling assets
@AshboDev AshboDev changed the title Add fix for compile error after upgrade.md's change from vite to mix fix: compile error following upgrade.md's vite to mix guide Jun 28, 2023
@timacdonald
Copy link
Member

@AshboDev the upgrade guide already mentions adding the "type": "module" to the package.json and also mentioned the postcss file changes that need to be made.

I don't think we want to recommend removing this or using module.export.

@AshboDev
Copy link
Contributor Author

AshboDev commented Jun 29, 2023

@AshboDev the upgrade guide already mentions adding the "type": "module" to the package.json and also mentioned the postcss file changes that need to be made.

I don't think we want to recommend removing this or using module.export.

Hi @timacdonald,

This is for the section of the guide to switch back from Vite to Mix - not for installing Vite itself. Following the guide on 2 new projects, both had the same error upon running npm run watch for these 2 files on both projects.

That's a new Laravel project, Jetstream install, then go from Vite to Mix, same error.

I'm replying from mobile but happy to add the error when at my desk at a more normal hour!

Cheers :)

@AshboDev
Copy link
Contributor Author

Here's the one for postcss:

ERROR in ./resources/css/app.css
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
C:\Users\Ash\Sites\mysite\postcss.config.js:1
export default {

And package.json:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Ash\Sites\mysite\webpack.mix.js from C:\Users\Ash\Sites\mysite\node_modules\laravel-mix\setup\webpack.config.js not supported.
webpack.mix.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename webpack.mix.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Users\Ash\Sites\mysite\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at module.exports (C:\Users\Ash\Sites\mysite\node_modules\laravel-mix\setup\webpack.config.js:11:5)
    at loadConfigByPath (C:\Users\Ash\Sites\mysite\node_modules\webpack-cli\lib\webpack-cli.js:1439:37)
    at async Promise.all (index 0)
    at async WebpackCLI.loadConfig (C:\Users\Ash\Sites\mysite\node_modules\webpack-cli\lib\webpack-cli.js:1454:35)
    at async WebpackCLI.createCompiler (C:\Users\Ash\Sites\mysite\node_modules\webpack-cli\lib\webpack-cli.js:1785:22)
    at async WebpackCLI.runWebpack (C:\Users\Ash\Sites\mysite\node_modules\webpack-cli\lib\webpack-cli.js:1890:20)
    at async Command.<anonymous> (C:\Users\Ash\Sites\mysite\node_modules\webpack-cli\lib\webpack-cli.js:912:21)
    at async Promise.all (index 1)
    at async Command.<anonymous> (C:\Users\Ash\Sites\mysite\node_modules\webpack-cli\lib\webpack-cli.js:1372:13) {
  code: 'ERR_REQUIRE_ESM'
}```

Setting the `type` to `commonjs` as mentioned in the error message done nothing and I get the exact same errors above with a fresh Laravel install (No jetstream or other packages). When I remove `type` from package.json, it all works (Providing you've updated `postcss.config.js` as I've done in my changes.

node 19.3.0
npm 9.7.2
mix 6.0.49

Happy to do more debugging if required.

Thanks
Ash

@jessarcher
Copy link
Member

Thanks @AshboDev!

I've made a few changes to match the Mix->Vite instructions and included a dedicated section on Tailwind and PostCSS.

Can you confirm whether these changes still resolve the error for you?

@AshboDev
Copy link
Contributor Author

AshboDev commented Jul 6, 2023

Hey @jessarcher,

Thanks for the feedback and updating the PR. I've just run through this on a fresh install:

Laravel 10
PHP 8.1.2
Node 19.3.0
NPM 9.7.2

All seemed OK besides one thing - which I'm not sure is related to the steps followed in the guide (But will double check later as I've not got time right now):

ERROR in ./resources/js/bootstrap.js 7:0-26
Module not found: Error: Can't resolve 'axios' in 'C:\Users\Ash\Sites\test\resources\js'
Did you miss the leading dot in 'resolve.extensions'? Did you mean '[".*",".wasm",".mjs",".js",".jsx",".json"]' instead of '["*",".wasm",".mjs",".js",".jsx",".json"]'?

bootstrap.js (Default from laravel new):

import axios from 'axios';
window.axios = axios;

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

The above error is resolved when I install laravel/jestream with livewire, so it appears to be installed with that.

Apart from that above (I believe unrelated) error - all is good, following the guide step by step.

Thanks!
Ash

@jessarcher
Copy link
Member

Thanks, @AshboDev!

@jessarcher jessarcher merged commit a672461 into laravel:main Jul 6, 2023
3 checks passed
@AshboDev AshboDev deleted the patch-1 branch July 7, 2023 09:54
tisnamuliarta added a commit to tisnamuliarta/laravel-shadcn that referenced this pull request Mar 11, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel-vite-plugin](https://togithub.com/laravel/vite-plugin) |
[`^0.7.8` ->
`^0.8.0`](https://renovatebot.com/diffs/npm/laravel-vite-plugin/0.7.8/0.8.1)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/laravel-vite-plugin/0.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/laravel-vite-plugin/0.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/laravel-vite-plugin/0.7.8/0.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/laravel-vite-plugin/0.7.8/0.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/vite-plugin (laravel-vite-plugin)</summary>

###
[`v0.8.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v081---2023-09-26)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.0...v0.8.1)

- \[0.8] Fix issue with `0.0.0.0` network resolution by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#241
- Upgrade vitest by
[@&#8203;sapphi-red](https://togithub.com/sapphi-red) in
[laravel/vite-plugin#246

###
[`v0.8.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v080---2023-08-08)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.7.8...v0.8.0)

- fix: compile error following upgrade.md's vite to mix guide by
[@&#8203;AshboDev](https://togithub.com/AshboDev) in
[laravel/vite-plugin#231
- Support Laravel Herd by
[@&#8203;claudiodekker](https://togithub.com/claudiodekker) in
[laravel/vite-plugin#233

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
tisnamuliarta added a commit to tisnamuliarta/laravel-shadcn that referenced this pull request Mar 11, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel-vite-plugin](https://togithub.com/laravel/vite-plugin) |
[`^0.8.0` ->
`^1.0.0`](https://renovatebot.com/diffs/npm/laravel-vite-plugin/0.7.8/1.0.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/vite-plugin (laravel-vite-plugin)</summary>

###
[`v1.0.2`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v102---2024-02-28)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.1...v1.0.2)

- \[1.x] Fix HMR issue when `resources/lang` directory doesn't exist and
a symlink is present in the root directory by
[@&#8203;jessarcher](https://togithub.com/jessarcher) in
[laravel/vite-plugin#285

###
[`v1.0.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v101---2023-12-27)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.0...v1.0.1)

- \[1.x] Simpler conditional by
[@&#8203;Jubeki](https://togithub.com/Jubeki) in
[laravel/vite-plugin#273
- \[1.x] Account for imported CSS files while cleaning by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#275
- \[1.x] Fix exit error messages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#276

###
[`v1.0.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v100---2023-12-19)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.1...v1.0.0)

- \[1.0] Drop CJS build and export types first by
[@&#8203;benmccann](https://togithub.com/benmccann) in
[laravel/vite-plugin#235
- \[1.x] Introduce `clean-orphaned-assets` binary by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#251
- \[0.8.x] Respect vite server.origin in viteDevServerUrl by
[@&#8203;nurdism](https://togithub.com/nurdism) in
[laravel/vite-plugin#255
- \[1.x] Vite 5 by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#269
- \[0.8.x] Fallback pages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#271
- \[1.x] Auto detect Valet / Herd TLS certificates by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#180

###
[`v0.8.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v081---2023-09-26)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.0...v0.8.1)

- \[0.8] Fix issue with `0.0.0.0` network resolution by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#241
- Upgrade vitest by
[@&#8203;sapphi-red](https://togithub.com/sapphi-red) in
[laravel/vite-plugin#246

###
[`v0.8.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v080---2023-08-08)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.7.8...v0.8.0)

- fix: compile error following upgrade.md's vite to mix guide by
[@&#8203;AshboDev](https://togithub.com/AshboDev) in
[laravel/vite-plugin#231
- Support Laravel Herd by
[@&#8203;claudiodekker](https://togithub.com/claudiodekker) in
[laravel/vite-plugin#233

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
tisnamuliarta added a commit to tisnamuliarta/laravel-shadcn that referenced this pull request Mar 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel-vite-plugin](https://togithub.com/laravel/vite-plugin) |
[`^0.7.5` ->
`^1.0.0`](https://renovatebot.com/diffs/npm/laravel-vite-plugin/0.7.8/1.0.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/vite-plugin (laravel-vite-plugin)</summary>

###
[`v1.0.2`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v102---2024-02-28)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.1...v1.0.2)

- \[1.x] Fix HMR issue when `resources/lang` directory doesn't exist and
a symlink is present in the root directory by
[@&#8203;jessarcher](https://togithub.com/jessarcher) in
[laravel/vite-plugin#285

###
[`v1.0.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v101---2023-12-27)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v1.0.0...v1.0.1)

- \[1.x] Simpler conditional by
[@&#8203;Jubeki](https://togithub.com/Jubeki) in
[laravel/vite-plugin#273
- \[1.x] Account for imported CSS files while cleaning by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#275
- \[1.x] Fix exit error messages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#276

###
[`v1.0.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v100---2023-12-19)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.1...v1.0.0)

- \[1.0] Drop CJS build and export types first by
[@&#8203;benmccann](https://togithub.com/benmccann) in
[laravel/vite-plugin#235
- \[1.x] Introduce `clean-orphaned-assets` binary by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#251
- \[0.8.x] Respect vite server.origin in viteDevServerUrl by
[@&#8203;nurdism](https://togithub.com/nurdism) in
[laravel/vite-plugin#255
- \[1.x] Vite 5 by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#269
- \[0.8.x] Fallback pages by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#271
- \[1.x] Auto detect Valet / Herd TLS certificates by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#180

###
[`v0.8.1`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v081---2023-09-26)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.8.0...v0.8.1)

- \[0.8] Fix issue with `0.0.0.0` network resolution by
[@&#8203;timacdonald](https://togithub.com/timacdonald) in
[laravel/vite-plugin#241
- Upgrade vitest by
[@&#8203;sapphi-red](https://togithub.com/sapphi-red) in
[laravel/vite-plugin#246

###
[`v0.8.0`](https://togithub.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v080---2023-08-08)

[Compare
Source](https://togithub.com/laravel/vite-plugin/compare/v0.7.8...v0.8.0)

- fix: compile error following upgrade.md's vite to mix guide by
[@&#8203;AshboDev](https://togithub.com/AshboDev) in
[laravel/vite-plugin#231
- Support Laravel Herd by
[@&#8203;claudiodekker](https://togithub.com/claudiodekker) in
[laravel/vite-plugin#233

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzguMSIsInVwZGF0ZWRJblZlciI6IjM3LjIzOC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
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

Successfully merging this pull request may close these issues.

3 participants