I have done everything in accordance with the docs.
I installed storybook, and then I changed the config file the way they say has to be done to make storybook work on Vite, which supports the element-plus library.
.storybook/main.js:
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.#(js|jsx|ts|tsx)'],
addons: ['#storybook/addon-links', '#storybook/addon-essentials'],
core: {
builder: '#storybook/builder-vite', // 👈 The builder enabled here.
},
}
Package.json:
{
"name": "elementui-practice",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview --port 4173",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"element-plus": "^2.2.17",
"node-sass": "^7.0.3",
"sass-loader": "^13.0.2",
"vue": "^3.2.38"
},
"devDependencies": {
"#babel/core": "^7.19.1",
"#storybook/addon-actions": "^6.5.12",
"#storybook/addon-essentials": "^6.5.12",
"#storybook/addon-interactions": "^6.5.12",
"#storybook/addon-links": "^6.5.12",
"#storybook/builder-vite": "^0.2.2",
"#storybook/testing-library": "^0.0.13",
"#storybook/vue3": "^6.5.12",
"#vitejs/plugin-vue": "^3.0.3",
"babel-loader": "^8.2.5",
"eslint": "^8.23.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-storybook": "^0.6.4",
"eslint-plugin-vue": "^9.5.1",
"sass": "^1.55.0",
"vite": "^3.0.9",
"vue-cli-plugin-storybook": "~2.1.0",
"vue-loader": "^16.8.3"
}
}
If I run only the element-plus (npm run dev), the library works.
If I run npm run storybook, element-plus styles are not applied to the components or elements. Normal css works, but element-plus components and styles do not work.
Add these code to storybook's preview.js
import { app } from '#storybook/vue3'; //I use Vue3
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
app.use(ElementPlus);
Related
I am trying to install VueJS in Laravel 8. If I run npm run dev command I am getting below error.
My prayer_time.vue file is like below.
<template>
<div>Welcome</div>
</template>
<script>
export default {
mounted() {
console.log("Example component mounted");
}
};
</script>
My package.json file is like below.
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"#popperjs/core": "^2.10.2",
"axios": "^0.21",
"bootstrap": "^5.2",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"vue": "^2.6.12",
"vue-loader": "^16.8.3",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"vue": "^3.2.45"
}
}
How can I run VueJS in laravel ?
I have npm 8.1.2 version installed. I created Vue2 project. All worked fine until I have installed Vuetify2 (npm add vuetify). Now, when I start the app using npm run serve the following error comes up:
ERROR Error loading D:\XYZ\project\vue.config.js:
ERROR TypeError: defineConfig is not a function TypeError:
defineConfig is not a function
I upgraded all existing packages to the newest versions:
{
"name": "project",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --open",
"build": "vue-cli-service build"
},
"dependencies": {
"core-js": "^3.26.0",
"npm-check-updates": "^16.3.15",
"vue": "^3.2.41",
"vue-router": "^4.1.5",
"vuetify": "^2.6.12",
"vuex": "^4.1.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~5.0.8",
"#vue/cli-plugin-router": "~5.0.8",
"#vue/cli-plugin-vuex": "~5.0.8",
"#vue/cli-service": "~5.0.8",
"sass": "~1.55.0",
"sass-loader": "^13.1.0",
"vue-cli-plugin-vuetify": "~2.5.8",
"vue-template-compiler": "^2.7.13",
"vuetify-loader": "^1.9.2"
}
}
and my vue.config.js looks like this:
const { defineConfig } = require('#vue/cli-service')
module.exports = defineConfig({
transpileDependencies: [
'vuetify'
]
})
I don't know where the problem is. I also have another Vue2+Vuetify2 project (which I created a few months ago) which works fine when I run it with npm run serve. But the new one is not working.
I'm getting this error when trying to run yarn run dev --port=4000
Here is the error:
Module build failed (from ./node_modules/babel-loader/lib/index.js): friendly-errors 16:52:26
Error: /Users/jacob/code/artistrepublik/elite-reviews/.nuxt/client.js: Cannot find module '#babel/preset-env/lib/utils'
Require stack:
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/polyfills-plugin.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/module-types.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/configuration.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/nuxt-route-meta/dist/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/core/dist/core.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at n (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/jiti/dist/v8cache.js:2:2364)
at PluginPass.Program (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/polyfills-plugin.js:15:34)
at newFn (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/visitors.js:175:21)
at NodePath._call (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:92:31)
at TraversalContext.visitQueue (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:116:16)
at TraversalContext.visitSingle (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:85:19)
at TraversalContext.visit (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:144:19)
at Function.traverse.node (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/index.js:82:17)
at traverse (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/index.js:62:12)
at transformFile (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/transformation/index.js:107:29)
at transformFile.next (<anonymous>)
friendly-errors 16:52:26
# multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
Here is my package.json:
{
"name": "my-project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt -r dotenv/config",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"test": "jest"
},
"dependencies": {
"#nuxtjs/axios": "^5.12.5",
"#nuxtjs/dotenv": "^1.4.1",
"#nuxtjs/pwa": "^3.3.4",
"#paypal/paypal-js": "^1.0.5",
"#vue/babel-preset-app": "^4.5.10",
"core-js": "^3.8.3",
"es6-promise": "^4.1.1",
"lodash": "^4.17.20",
"moment": "latest",
"moment-timezone": "^0.5.32",
"noty": "^3.2.0-beta",
"nuxt": "^2.14.12",
"nuxt-i18n": "^6.18.0",
"nuxt-route-meta": "^1.0.3",
"nuxt": "^2.14.6",
"nuxt-i18n": "^6.15.1",
"nuxt-route-meta": "^1.0.1",
"nuxt-stripe-module": "^3.0.1",
"object-to-formdata": "^4.1.0",
"pluralize": "latest",
"vee-validate": "^3.4.5",
"sib-api-v3-sdk": "github:sendinblue/APIv3-nodejs-library",
"vue-carousel": "^0.18.0",
"vue-chartist": "^2.2.1",
"vue-material-design-icons": "^4.11.0",
"vuejs-noty": "^0.1.3",
"vue-plyr": "^7.0.0",
"vuetify-media-player": "^0.8.1"
},
"devDependencies": {
"#babel/core": "^7.12.10",
"#mdi/font": "^5.9.55",
"#nuxt/types": "^2.14.12",
"#nuxtjs/style-resources": "^1.0.0",
"#nuxtjs/vuetify": "^1.11.3",
"#vue/test-utils": "^1.1.2",
"babel-jest": "^26.6.3",
"babel-plugin-component": "^1.1.0",
"cross-env": "^5.2.0",
"dotenv": "^8.2.0",
"jest": "^26.6.3",
"material-design-icons-iconfont": "^6.1.0",
"node-sass": "^4.14.1",
"nodemon": "^1.18.9",
"sass-loader": "^7.3.1",
"vue-jest": "^3.0.4"
}
}
And here is my .babelrc:
{
"env": {
"test": {
"presets": [
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
}
}
I have tried deleting the node_modules folder along with removing the yarn.lock file with no luck. The babel version looks correct. This error only popped up after me playing around with some code (not the package.json) - which is an unrelated error.
Any help would be appreciated!
#babel/preset-env updated,
use old version 7.12.17
https://www.npmjs.com/package/#babel/preset-env/v/7.12.17
This issue drove me crazy for a few hours too.
The solution is to add to nuxt.config.js into build section:
/*
** Build configuration
*/
build: {
babel: {
presets(env, [ preset, options ]) {
return [
[ "#babel/preset-env", options ]
]
}
},
Make sure you have that thing installed:
npm install --save-dev #babel/preset-env
or in your case with yarn
Updated:
Then I encountered another error
regeneratorRuntime is not defined
Here is working part from my config.nuxt.js
build: {
babel: {
presets({isServer}) {
const targets = isServer ? { node: 'current' } : { ie: 11 }
return [
[ require.resolve("#babel/preset-env"), { targets } ]
]
},
plugins: [
"#babel/syntax-dynamic-import",
"#babel/transform-runtime",
"#babel/transform-async-to-generator"
]
},
I did the following:
npm uninstall #babel/preset-env
npm install #babel/preset-env#7.12.13
The latest version seems to have this issue resolved, try updating Nuxt to v2.15.2
https://nuxtjs.org/docs/release-notes
lib/utils.js was dropped for #babel/preset-env#7.13.0 and above
as stated above installing the old 7.12.17 might work
for monorepos it may not be enough. upgrading nuxtjs to 2.15.x did the trick for me
I had same error when deploying to ElasticBeanstalk
Error: /var/app/current/.nuxt/client.js: Cannot find module '#babel/preset-env/lib/utils'
upgrading from "nuxt": "v2.14.12", to "nuxt": "v2.15.2", seem to have solved the problem
npm uninstall #babel/preset-env
npm install #babel/preset-env#7.12.17
I just had the same problem, There's some issue with the newest #babel/preset-env within the Nuxt.
install the old version and it should work just fine
npm i #babel/preset-env#7.12.17 -S
You can try to do:
// package.json
"devDependencies": {
+ "#babel/preset-env": "7.12.17",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"node-sass": "^4.14.1",
"sass-loader": "^8.0.2",
"style-loader": "^1.0.0"
},
// package-lock.json
"#babel/preset-env": {
+"version": "7.12.17",
...,
"#nuxt/babel-preset-app": {
"requires": {
"#babel/preset-env": "7.12.17",
...
}
}
}
I have used an external component datetimepicker in my component and it works fine as shown below when I run the project.
But while building for production as web component to get the min.js files inside dist directory, not getting CSS reference of that external component datetimepicker in the received js files inside the dist directory. It does not render styles of the datetimepicker field. It is displaying like below. Is there any solution for that?
I have executed below command:
$ npm install vuejs-datetimepicker
And used below code for that
<td align="left">
<datetime format="DD-MM-YYYY h:i:s" width="280px" v-model="dateTime"></datetime>
</td>
import datetime from 'vuejs-datetimepicker';
export default {
components: {
datetime
}
}
And I used the command npm run build to build as web component.
Attaching my package file below:
{
"name": "ABC",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --target wc-async --name common-apps
./src/App.vue",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.4",
"vue": "^2.6.11",
"vuejs-datetimepicker": "^1.1.13",
"vuex": "^3.1.2"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.2.0",
"#vue/cli-plugin-eslint": "^4.2.0",
"#vue/cli-plugin-unit-jest": "^4.2.0",
"#vue/cli-plugin-vuex": "^4.2.0",
"#vue/cli-service": "^4.2.0",
"#vue/eslint-config-prettier": "^6.0.0",
"#vue/test-utils": "1.0.0-beta.31",
"babel-eslint": "^10.0.3",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-vue": "^6.1.2",
"prettier": "^1.19.1",
"sass": "^1.25.0",
"sass-loader": "^8.0.2",
"vue-template-compiler": "^2.6.11"
}
}
I fixed this issue just by executing the command npm install style-loader css-loader --save in the terminal.
I'm trying to use express library in main.js file. It works fine on my dev build, but when I package the app I get
Error: Cannot find module 'express'
I'm not quite sure how electron main thread works, is it packaged separately by some other build tool, and do I need to define(include) package manually? My app is packaged by webpack, and I have included libraries in package.json. Every sample I have found just includes express library and moves on, I can't find any additional steps for this.
package.json
{
"name": "basic-electron-react-boilerplate",
"version": "0.7.0",
"description": "Minimal and modern react+electron+webpack boilerplate",
"author": "Phillip Barbiero",
"homepage": "https://github.com/pbarbiero/basic-electron-react-boilerplate",
"repository": {
"type": "git",
"url": "https://github.com/pbarbiero/basic-electron-react-boilerplate.git"
},
"build": {
"appId": "your.id",
"mac": {
"category": "your.app.category.type"
}
},
"license": "MIT",
"main": "main.js",
"scripts": {
"prod": "webpack --config webpack.build.config.js && electron --noDevServer .",
"test": "node test.js",
"dev": "webpack-dev-server --hot --host 0.0.0.0 --config=./webpack.dev.config.js",
"build": "webpack --config webpack.build.config.js",
"package": "webpack --config webpack.build.config.js",
"postpackage": "electron-packager ./ --out=./builds",
"pack": "electron-builder --dir",
"dist": "electron-builder"
},
"devDependencies": {
"#babel/core": "^7.1.2",
"#babel/plugin-proposal-class-properties": "^7.1.0",
"#babel/plugin-proposal-export-default-from": "^7.0.0",
"#babel/plugin-proposal-object-rest-spread": "^7.0.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-es2017": "^7.0.0-beta.53",
"#babel/preset-react": "^7.0.0",
"babel-core": "^6.24.1",
"babel-loader": "^8.0.4",
"babel-plugin-lodash": "^3.3.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babili-webpack-plugin": "^0.1.2",
"body-parser": "^1.18.3",
"css-loader": "^0.28.1",
"electron": "^1.7.8",
"electron-builder": "^20.28.4",
"electron-packager": "^9.1.0",
"express": "^4.16.4",
"extract-text-webpack-plugin": "^3.0.1",
"file-loader": "^1.1.5",
"html-webpack-plugin": "^2.28.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"request": "^2.88.0",
"style-loader": "^0.19.0",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.4.5"
},
"dependencies": {
"electron-fetch": "^1.2.1",
"electron-require": "^0.3.0",
"express": "^4.16.4",
"faker": "^4.1.0",
"lodash": "^4.17.11",
"moment": "^2.22.2",
"rc-time-picker": "^3.4.0",
"react-async-script-loader": "^0.3.0",
"react-dropdown": "^1.6.2",
"react-places-autocomplete": "^7.2.0",
"request": "^2.88.0",
"resolve-url-loader": "^3.0.0",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.82.5",
"styled-components": "^4.0.2"
}
}
You can run Express server inside Electron. Here is a sample repo for running express inside Electron.
You can fork a child process to run express app as follows
app = require("electron").remote.app),
node = require("child_process").fork(
`${app.getAppPath()}/express-app/bin/www`,
[],
{
stdio: ["pipe", "pipe", "pipe", "ipc"]
});
The express app used here is a generated one using express-generator.
The problem with your approach is that you are maintaining a single package.json file for both Electron and Express. Checkout Electron-React-Boilerplate, here i have two separate npm installation locations one is for Electron alone and other is for React stuffs. Electron-packager and Electron-builder works using this pattern. This is the reason why your process on main thread throws
Error: Cannot find module 'express'