Open tooppoo opened 3 years ago
I got a build error when using the followings.
The error is as follows.
╭───────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ ✖ Nuxt Fatal Error │ │ │ │ Error: Cannot find module '0' │ │ Require stack: │ │ - /Users/path/to/app/node_modules/@nuxt/core/dist/core.js │ │ │ ╰───────────────────────────────────────────────────────────────────────────────────────────────╯
In my nuxt.config.js, I was specifying build.postcss.plugins as an array. On the other hand, @nuxt/postcss8 uses object as value of build.postcss.plugins.
nuxt.config.js
build.postcss.plugins
My nuxt.config.js is like the following.
import path from 'path' // (...) export default { // (...) build: { postcss: { plugins: [ 'plugin-a', 'plugin-b' ] } } }
@nuxt/postcss8 uses defu to merge the settings. When defu merges an object against an array, it uses the array index as the object's key.
@nuxt/postcss8
defu
Thus, defu would build build.postcss.plugins like the following.
{ build: { postcss: { plugins: { '0': { /* option for plugin-a */ }, '1': { /* option for plugin-b */ }, 'autoprefixer': {} } } } }
You can reproduce this by checking out https://github.com/nuxt/postcss8/commit/a57775a48f7d79b2f05bb9e492133492c66cf114 and then running yarn dev.
yarn dev
Select the format corresponding to build.postcss.plugins as defined in nuxt.config.js. If build.postcss.plugins is an array, use array format, if it is an object, use object format to merge (https://github.com/nuxt/postcss8/commit/06f3bee61136d02e1271ac74fac6f2804328cc52).
yarn test
yarn dev:legacy
Jest
src/index.ts
TypeError: defu_1.default is not a function
dist/index.js
dev:legacy
postcss-loader
legacy
Problem
I got a build error when using the followings.
The error is as follows.
Cause
In my
nuxt.config.js
, I was specifyingbuild.postcss.plugins
as an array. On the other hand, @nuxt/postcss8 uses object as value ofbuild.postcss.plugins
.My
nuxt.config.js
is like the following.@nuxt/postcss8
usesdefu
to merge the settings. Whendefu
merges an object against an array, it uses the array index as the object's key.Thus,
defu
would buildbuild.postcss.plugins
like the following.You can reproduce this by checking out https://github.com/nuxt/postcss8/commit/a57775a48f7d79b2f05bb9e492133492c66cf114 and then running
yarn dev
.Solution
Select the format corresponding to
build.postcss.plugins
as defined innuxt.config.js
. Ifbuild.postcss.plugins
is an array, use array format, if it is an object, use object format to merge (https://github.com/nuxt/postcss8/commit/06f3bee61136d02e1271ac74fac6f2804328cc52).Test
yarn test
yarn dev
yarn dev:legacy
Notes.
Jest
.src/index.ts
and run the test,TypeError: defu_1.default is not a function
gotten.dist/index.js
in the test.dev:legacy
because we wanted to check the behavior with two differentnuxt.config.js
.postcss-loader
deprecates the object format, I named the configuration using the object format aslegacy
.