I am updating #vue/cli-service from 4.5.15 to 5.0.6 in my project and it leads to errors when bundling:
Module not found: Error: Can't resolve '/assets/img/my-image.png' in 'C:\some-path-here\folder-name'
The image is defined in MyComponent.vue as follows:
<style>
.my-component {
background: url(/assets/img/my-image.png);
}
</style>
These are also some of my dependencies:
"dependencies": {
"vue": "^2.7.0"
},
"devDependencies": {
"#vue/cli-service": "^5.0.6",
"copy-webpack-plugin": "^11.0.0",
"sass": "^1.53.0",
"sass-loader": "^13.0.2",
"vue-svg-loader": "^0.16.0"
}
This is my understanding of what happens:
Webpack 5 is configured in Vue CLI 5.0.6 to find my-image.png somewhere in my project. This file doesn't exist in my project and Webpack will never find it.
Webpack 4 is not configured in Vue CLI 4.5.15 to find any assets in my project and it keeps paths as is.
Basically, I don't want Webpack to search for any assets (i.e. images and fonts) in my project, I want it to keep paths as is. A browser will find my assets based on the paths I defined myself.
Is there a way to prevent resolving particular paths in Webpack / Vue CLI? For example, if they start with "/assets" or end with particular file extensions?
I tried something like this but it does not help:
configureWebpack: {
plugins: [
new webpack.IgnorePlugin({
resourceRegExp: /^\.(png|woff)$/
})
]
}
Related
As the title says, ESLint is complaining with this error message:
ESLint: Unable to resolve path to module '#vercel/analytics/react'.(import/no-unresolved)
In the line: import { Analytics } from '#vercel/analytics/react';
When following the instructions from this Vercel quickstart guide, using Next.js.
To sum up, the instructions are:
1- install package via NPM
npm install #vercel/analytics
2- in /pages/_app.tsx file, import it:
import { Analytics } from '#vercel/analytics/react';
function MyApp({ Component, pageProps }) {
return (
<>
<Component {...pageProps} />
<Analytics />
</>
);
}
export default MyApp;
My packages used:
"next": "^12.1.0",
"react": "17.0.2",
"#typescript-eslint/eslint-plugin": "^4.33.0",
"#typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-next": "^12.2.5",
"eslint-config-prettier": "^6.15.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.10.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^24.7.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.0",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-testing-library": "^3.10.2",
The NPM package installed, has this folder structure:
/node_modules/#vercel
analytics/
dist/
react/
index.cjs
index.d.ts
index.js
index.cjs
index.d.ts
index.js
package.json
tsconfig.json
...
Notice how the path in node_modules actually is '#vercel/analytics/dist/react' rather than just '#vercel/anaylitics/react' as the instructions state to do in the code to use it.
But, when CTRL+click'ing on the variable imported Analytics, my IDE properly navigates me to the definition in node_modules, to the file #vercel/analytics/dist/react/index.d.ts, which is defined like so:
// ./node_modules/#vercel/analytics/dist/react/index.d.ts
// ...
declare function Analytics(props: AnalyticsProps): JSX.Element;
export { Analytics };
My ESLint config related to the import/ module is
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
paths: ['src'],
},
},
},
If I import it as this instead:
import { Analytics } from '#vercel/analytics/dist/react'
then ESlint doesn't complain, but TSC does, with this error message:
TS2305: Module '"#vercel/analytics/dist/react"' has no exported member 'Analytics'.
Which also doesn't seem to make sense as the IDE is still finding the definition, and I can also see how the export { Analytics } line is there, so it should work...
What ESlint config or steps should I take differently to make this work without any lint/compiler errors?
When using eslint you will need to use the plugin: eslint-import-resolver-typescript with version 3.1.0 or later.
We also merged this version into eslint-config-next in this Pull Request. So this issue should also be resolved by upgrading to the latest package (13.0.4)
There is also a issue on our Github repo which with the solution: https://github.com/vercel/analytics/issues/18#issuecomment-1318424277
I have a question into vercel for a solution as I have the same issue. Probably to be expected since this is a beta product. I added the following line to my _app.js file in the meantime which allowed me to bypass the linting error and deploy to vercel. I have tested and the analytics is showing so must simply be a bug.
...
// eslint-disable-next-line import/no-unresolved
import { Analytics } from "#vercel/analytics/react";
...
Try this way
//tsconfig.json
"compilerOptions": {
"baseUrl": "./",
"paths": {
"#vercel/analytics/react": ["./node_modules/#vercel/analytics/dist/react"]
}
}
i have a legacy project and wanted to start using Vue.js single file components using the CDN. I did bump into some plugins such as https://github.com/FranckFreiburger/vue3-sfc-loader.
Is there any solution from CDN point of view that we can:
generic mount to the root of the page / body ?
add every *.vue file from /components folder?
Then we could call those components anywhere in the existing page.
I believe the plugin https://github.com/FranckFreiburger/vue3-sfc-loader only allows us to mount to a specific div#app and add a custom template (at least following the examples provided)
Cheers!
After spending lots of time in this investigation, I went for the Vue Web Components approach
Adding all the components to a /components folder, we will just need to have a package.json like the following
"scripts": {
"build": "node_modules/.bin/vue-cli-service build --target wc '/components/*.vue' --name my-app",
"watch": "node_modules/.bin/vue-cli-service build --watch --target wc '/components/*.vue' --name my-app"
},
"dependencies": {
"#vue/cli-service": "^4.5.12",
"vue": "^2.6.12",
"vue-template-compiler": "^2.6.12"
}
And add the following vue.config.js file in order to
have only one file in the bundle
// vue.config.js
module.exports = {
configureWebpack: {
// No need for splitting
optimization: {
splitChunks: false
}
}
}
Then by adding
<script src="https://unpkg.com/vue"></script>
<script src="./dist/my-app.min.js"></script>
to the page, we are able to use the components (see dist/demo.html to confirm the final name of the components)
And for me this delivered what was needed. Hope someone can find it useful.
Strange it seems that I am the first person to experience this "flow" preset error on the interwebz..
My .babelrc is configured as
{
presets: ["react-native", "flow"]
}
My package.json includes the following dev dependencies:
{
"babel-cli": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"flow-bin": "^0.38.0"
}
Yet I'm receiving the following error:
TransformError: /Users/Progoogler/App/ios/src/index.js: Couldn't find
preset "flow" relative to directory "/Users/Progoogler/App"
Has anyone experienced this problem before with flow?
I want to integrate relay with react native.
I am getting following error:
getBabelRelayPlugin is not defined while processing preset
I used following steps to integrate react native with relay
1.Back up your project.
2. Make sure you have your GraphQL server ready and your schema.json at hand too. For more details about the latter two visit the React-Relay project page.
Ensure that you’re using npm version 3 or greater.
3.If React Native's packager (react-native start) is running somewhere in the background, you should stop it now.
4.Run: watchman watch-del-all
5.Delete the ./node_modules directory from your project.
6.Edit your package.json file, make sure it has the following:
"dependencies": {
"react": "^0.14.7",
"react-native": "facebook/react-native",
"react-relay": "^0.7.3"
},
"devDependencies": {
"babel-core": "^6.6.4",
"babel-preset-react-native": "^1.4.0",
"babel-relay-plugin": "^0.7.3"
}
Babel version is especially important. Make sure that your project uses babel 6.5 or later, we need it for the passPerPreset feature in .babelrc file.
7.Create a new file .babelrc and place it in your project's directory:
{
"presets": [
"./scripts/babelRelayPlugin",
"react-native"
],
"passPerPreset": true
}
8.Create a new file in your project's directory called babelRelayPlugin.js with the following content:
const getBabelRelayPlugin = require('babel-relay-plugin');
const schema = require('./schema.json');
module.exports = { plugins: [getBabelRelayPlugin(schema.data)] };
9Copy your schema.json file to the project's directory too.
10.Run: npm install
I'm trying to load jquery + jquery-ui + bootstrap inside my project throught NPM and gulp.
My configuration is this:
Package.json
"browser": {
"jquery": "/node_modules/jquery/dist/jquery.js",
"jquery-ui": "/node_modules/jquery-ui-browserify/jquery-ui.js"
},
"browserify-shim": {
"jquery": "$",
"jquery-ui": {
"exports": "jquery-ui",
"depends": [ "jquery:jQuery" ]
}
},
"browserify": {
"transform": [ "browserify-shim" ]
},
"dependencies": {
"bootstrap": "^3.3.6",
"jquery": "2.1.0",
"jquery-ui-browserify": "^1.11.0-pre-seelio",
}
gulpfile.js
gulp.task('browserify', function(){
return browserify([
'node_modules/jquery/dist/jquery.js',
'node_modules/jquery-ui-browserify/dist/jquery-ui.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
])
.bundle()
.pipe(source('core.js'))
.pipe(buffer())
.pipe(gulp.dest('build/js'));
});
Then I load core.js with assetic from my index.php but I get this error:
Uncaught ReferenceError: jQuery is not defined
What am I doing wrong?
Thank you.
I don't know what you're trying to do there but keep in mind that what you should pass to the browserify instance is the entry point of your application, not your dependencies.
Then in your application you can use the require function to load those dependencies:
var $ = require('jquery');
While compiling browserify will autonomously do two things for you:
He will put into your bundle any library you required.
He will resolve your require statements by replacing them with a reference to the bundled copy of that library.
As long as the library is installed through npm you don't need any additional configuration. On the other hand if the library is situated in an unconventional location you'll need to tell browserify how to resolve it.
Anyway you can find more documentation on the repo's readme