Vue cannot use the <script import>? - vue.js

I was making a website in VueJS but it isn't working. App.vue at the top has
<script setup>
import Page from './components/Page.vue';
import Top from './components/Top.vue';
</script>
When I try to run dev mode: vite dev (npm run dev) or try to build it: vite (npm run build) it dosent like the last > at </script>
Note: I'm using JS instead of TS
It will not compile or even run the dev server.
ERROR:
Failed to parse source for import analysis because the content contains invalid JS syntax. Install #vitejs/plugin-vue to handle .vue files.
11:07:43 am [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install #vitejs/plugin-vue to handle .vue files.
Plugin: vite:import-analysis
File: D:/Developing/denhamrocknet/home/denhamrockjs/src/App.vue
1 | <script setup>
2 | import Page from '.Page.vue';
3 | import Top from '.Top.vue';
4 | </script>
| ^
5 |
6 |
at formatError (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40862:46)
at TransformContext.error (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40858:19)
at TransformContext.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37530:22)
at async Object.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:41111:30)
at async loadAndTransform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37373:29)
Failed to parse source for import analysis because the content contains invalid JS syntax. Install #vitejs/plugin-vue to handle .vue files.
11:08:30 am [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install #vitejs/plugin-vue to handle .vue files.
Plugin: vite:import-analysis
File: D:/Developing/denhamrocknet/home/denhamrockjs/src/App.vue
1 | <script setup>
2 | import Top from './components/Top.vue';
3 | import Page from './components/Page.vue';
4 | </script>
| ^
5 |
6 |
at formatError (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40862:46)
at TransformContext.error (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:40858:19)
at TransformContext.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37530:22)
at async Object.transform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:41111:30)
at async loadAndTransform (file:///D:/Developing/denhamrocknet/home/denhamrockjs/node_modules/vite/dist/node/chunks/dep-49b3b5ea.js:37373:29)
END
I have no idea why. Ive found out that setting: module.exports = { publicPath: '' } otherwise it is just a blank page although when I do I get this error and a white page.
PS: Anything helps! Ill try anything. I'm desperate for it to work.
Fixed Issue!

I FOUND A FIX!
I just removed: module.exports = { publicPath: '' } from my config and now it works! I must have made an error, added the code, fixed the error, and now removed the bad code.
Hope this helps anyone who has the same issue!

Related

Nuxt 3 with OfficeJS or Office Add-ins

I can run Office Add-ins with Vue 3 but I can't implement them into Nuxt 3. Does anyone have any experience with that?
Tried solutions:
https://github.com/nuxt/nuxt.js/issues/10097
Office.JS but in Nuxt
I want to see one working example in Nuxt 3 as Vue.
Example Doc for Vue:
https://learn.microsoft.com/en-us/office/dev/add-ins/quickstarts/excel-quickstart-vue
============ Edited ============
Working setup for Vue - This is Javascript;
vue create test-addin
yo office # Selecting manifest only.
Able to use "window.Office"
// ./src/main.js
import { createApp } from 'vue'
import App from './App.vue'
window.Office.onReady(() => {
createApp(App).mount('#app')
})
Didn't install any plugin or modules for Vue.
Same way for Nuxt 3 - This is TypeScript;
npx nuxi init test-addin
yo office # Selecting manifest only.
Cannot use "window.Office"
Error:
Property 'Office' does not exist on type 'Window & typeof globalThis'.ts(2339)
Installed #types/office-js but don't know how to implement it correctly for Nuxt 3.

Jest transformIgnorePatterns can't transpile vee-validate with pnpm

I have a Nuxt app that runs with pnpm and I'd like to test it using Jest and the vee-validate library.
Whenever I launch my tests, I get this error:
FAIL test/integration/components/ui/RegistrationForm.test.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/my-project/node_modules/.pnpm/vee-validate#3.4.14_vue#2.6.14/node_modules/vee-validate/dist/rules.js:889
export { alpha, alpha_dash, alpha_num, alpha_spaces, between, confirmed, digits, dimensions, double, email, excluded, ext, image, integer, is, is_not, length, max, max_value, mimes, min, min_value, numeric, oneOf, regex, required, required_if, size };
^^^^^^
SyntaxError: Unexpected token 'export'
34 | } from '#nuxtjs/composition-api';
35 | import { extend, ValidationProvider } from 'vee-validate';
> 36 | import {
| ^
37 | min_value as minValue,
38 | max_value as maxValue,
39 | } from 'vee-validate/dist/rules';
at Runtime.createScriptFromCode (node_modules/.pnpm/jest-runtime#28.1.1/node_modules/jest-runtime/build/index.js:1796:14)
at Object.<anonymous> (components/form/fields/CalendarField.vue:36:1)
at Object.<anonymous> (components/form/fields/FormField.vue:14:1)
I tried to add the option transformIgnorePattern inside jest.config.js but it's not working at all.
This is what I tried:
transformIgnorePatterns: ['/node_modules/(?!vee-validate/dist/rules)']
transformIgnorePatterns: ['/node_modules/(?!(.*vee-validate/dist/rules))/']
The only option that works for me is to import the UMD build but I lose all the benefit of tree-shaking.
Sources
https://github.com/logaretm/vee-validate/issues/2310
https://github.com/facebook/jest/issues/2081#issuecomment-699558143
https://qiita.com/tamonmon/items/6392c1680ef498a8c816
I ran into the same problem and was able to fix it by adjusting my jest.config.js file. I did three things there:
add "vee-validate/dist/rules": "babel-jest", to transform: {}
add the file path to transformIgnorePatterns like this: transformIgnorePatterns: ["/node_modules/", "/components/views/*", "node_modules/vee-validate/dist/rules"],
add isolatedModules to true in ts-jest like: globals: {
"ts-jest": {
isolatedModules: true,
babelConfig: true,
},
},
Since this response is late to for the op, I hope this helps atleast someone :)

PrimeVue Toast Component Error: Can't resolve './ToastMessage' in */toast

I'm currently starting a new project with vuejs and wanted to use primevue for some components.
My knowledge with VueJS in general is not the best, because I'm just getting started with it.
My application has a webpack based build with vue-loader configured, so thats how primevue is getting installed.
I was trying to use the Toast-Component, but when importing Toast from 'primevue/toastservice' webpack throws these two errors:
ERROR in ./node_modules/primevue/components/toast/Toast.vue?vue&type=script&lang=js& (./node_modules/vue-loader/lib??vue-loader-options!./node_modules/primevue/components/toast/Toast.vue?vue&type=script&lang=js&)
Module not found: Error: Can't resolve './ToastMessage' in '*/node_modules/primevue/components/toast'
# ./node_modules/primevue/components/toast/Toast.vue?vue&type=script&lang=js& (./node_modules/vue-loader/lib??vue-loader-options!./node_modules/primevue/components/toast/Toast.vue?vue&type=script&lang=js&) 11:0-42 86:24-36
# ./node_modules/primevue/components/toast/Toast.vue?vue&type=script&lang=js&
# ./node_modules/primevue/components/toast/Toast.vue
# ./node_modules/primevue/toast.js
# ./src/main.js
and
ERROR in ./node_modules/primevue/components/toast/Toast.vue?vue&type=style&index=0&lang=css& (./node_modules/vue-loader/lib??vue-loader-options!./node_modules/primevue/components/toast/Toast.vue?vue&type=style&index=0&lang=css&) 97:0
Module parse failed: Unexpected token (97:0)
File was processed with these loaders:
*./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
|
-> .p-toast {
| position: fixed;
| width: 20em;
# ./node_modules/primevue/components/toast/Toast.vue?vue&type=style&index=0&lang=css& 1:0-118 1:134-137 1:139-254 1:139-254
# ./node_modules/primevue/components/toast/Toast.vue
# ./node_modules/primevue/toast.js
# ./src/main.js
I import the Component as following:
import Vue from "vue";
import App from "./App/App.vue";
import Toast from 'primevue/toast';
import ToastService from 'primevue/toastservice';
Vue.use(ToastService);
Vue.component('Toast', Toast);
new Vue({
render: h => h(App)
}).$mount("#app");
I already tried importing/using the 'Toast' component in my App.js or in other files where i mainly wanna use those Toasts without success.
If I leave out the Toast all works fine, so the ToastService seems alright.
So if theres anybody who uses primevue and also ran into this problem and found a solution I thank you all in advance.
npm install mitt
solves the first issue. It is included in devDependencies of the primevue package, but for some reasons its not installed.
I have a solution for your second error, but not sure how to fix your first "Can't resolve" error, as I am still figuring that one out.
What does your webpack config look like? Do you specify a rule for CSS files? If the component uses a <style> block you need to tell webpack how to handle this.
Specify a rule for .css files, and it will also apply the same to <style> blocks in .vue files. Without this, webpack does not know how to parse the blocks.
So make sure your webpack.config.js rules section has the following CSS part in it (or something similar):
rules: [
{
test: /\.vue$/,
use: 'vue-loader'
},
// the below will apply to both plain `.css` files AND `<style>` blocks in `.vue` files
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
}
]
Also make sure to install the relevant tools in your package.json.
I solved something similar, so see my question and answer for more detailed info.

React-native jest test giving unexpected token

Getting an unexpected token from the component class. Looking for advice on how I can proceed.
The failure:
● Test suite failed to run
C:/../react-native/jest/mockComponent.js: Unexpected token (20:23)
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
18 |
19 | const Component = class extends SuperClass {
> 20 | static displayName = 'Component';
| ^
21 |
22 | render() {
23 | const name =
This worked for me https://github.com/expo/expo/issues/2595#issuecomment-440966998
I think the problem was having jest and jest-expo installed
For me, this worked:
"transformIgnorePatterns": [
"/node_modules/(?!sentry|react-native).+\\.js$",
],
Notice that you must list there all your node_modules
/Users/guillermo/alibrate/alibrate-mobile/node_modules/react-native/jest/mockComponent.js:20
static displayName = 'Component';

React native pure js module with flow

I'm trying to publish my first react native pure js module which uses flow. I'm having a hard time.
My repo is here - https://github.com/Noitidart/react-native-buttonex
Source is in ./src/index.js. I use flow there. So I have done in my repo npm i flow-bin#0.57.3 --save-dev.
I then simply did a npm publish. Is there anything else I need to do?
It is not able to be used in Expo.
Doing:
import Button from 'react-native-buttonex' // ERROR. The Expo team has been notified.
Adds that "Error: expo team has been notified". And trying to run it shows red box with "Failed to download module".
I thought to stip the flowtypes so I added .babelrc with:
{
"presets": ["flow"]
}
But when I run babel I get error:
SyntaxError: src/index.js: Unexpected token (29:10)
27 |
28 | class Button extends Component<Props, State> {
> 29 | state = {
| ^
30 | activeAnim: new Animated.Value(0)
31 | }
It seems like its not liking the ES2017 stuff which is normal for react-native.
May you please guide m on how to properly publish this?