I've been trying to learn AWS's CDK and one of my attempts involved using a seperate repositories for both the infrastructure and the application itself.
My application repository is the bog standard vite#latest install. No changes.
I'm having issues where when i deploy, the build is crashing with codeBuilds log stating src/App.tsx(2,23): error TS2307: Cannot find module './assets/react.svg' or its corresponding type declarations.
I've tried adjusting the tsconfig to include an #types folder with declarations for svg but this didn't work at all. It just gave more typescript errors.
I feel like i'm missing something really silly.
My CDK Pipeline:
const pipeline = new CodePipeline(this, "CahmFrontendPipeline", {
pipelineName: "CahmFrontendPipeline",
synth: new ShellStep("Synth", {
input: CodePipelineSource.gitHub("myuser/myrepo", "master", {
authentication: cdk.SecretValue.secretsManager("MY_SECRET"),
}),
primaryOutputDirectory: "dist",
commands: [
"cd frontend",
"npm i",
"npm run build",
"npx cdk synth",
],
}),
});
This all works right till the codebuild. I've tried changing the image it's using as well but to no avail. Has anyone had this problem and might be able to point me in the right direction?
Things get confusing because paths act differently between dev and build (prod). I created a very simple example sandbox to help visual things using the Vite starter app. I would also recommend reading the Static Asset Handling. Also incredibly useful are the Vite Build Options which let you change where files are output.
Ideally, you want to use import reactSVG from './assets/react.svg' at the top of your component, then reference that src in the render using src={reactSVG). Both dev and build will be happy with that.
Or you should use an absolute path like /assets/react.svg, removing the . in front.
Besides the sandbox above, I wrote detailed notes on what's happening inline above each image to help the understanding.
import { useState } from "react";
import reactLogo from "./assets/react.svg";
import "./App.css";
function App() {
const [count, setCount] = useState(0);
return (
<div className="App">
<div>
<a href="https://vitejs.dev" target="_blank">
{/**
* In dev, /vite.svg defaults to the "/public/vite.svg"
* In build/prod, /vite.svg defaults to "/dist/vite.svg"
* Use absolute paths or imports (below) when possible.
*/}
<img
src="/vite.svg"
className="logo"
alt="Vite logo"
width="25"
height="25"
/>
</a>
<a href="https://reactjs.org" target="_blank">
{/**
* Due to import magic, this works in both dev / build (prod)
* Use imports or absolute paths when possible.
*/}
<img
src={reactLogo}
className="logo react"
alt="React logo"
width="25"
height="25"
/>
</a>
{/**
* Here is where things go wrong with the default configuration:
*
* Example --- src="./assets/react.svg" won't work by default. Why?
* In development, "./" equates to your project root, "/"
*
* In a basic Vite project, root contains "src", "public", and "dist", if you ran the `npm run build` command.
* As you can see, there is no "assets" folder in project root. It's only contained
* within "src" or the "dist" folder. This is where things get interesting:
*
* When you "build" your app, Vite appends unique strings at the end of your compiled .js
* files in order to avoid cache side-effects on new deployments in the front-end.
*
* So in the built app folder ("dist"), your assets will look something like this:
*
* /dist/assets/react-35ef61ed.svg
* /dist/assets/index-d526a0c5.css
* /dist/assets/index-07a082e1.js
*
* As you can see, there is no "/assets/react.svg". It does not exist in the build,
* which is why it's recommended that you import images at the top of your component
* for local assets. You can use remote assets as inline string paths. ("https://...")
*/}
<a href="https://vitejs.dev" target="_blank">
<img
src="./assets/react.svg"
className="logo"
alt="Never be visible"
width="25"
height="25"
style={{ border: "1px red solid" }}
/>
</a>
{/* only works in dev, non-build */}
<a href="https://vitejs.dev" target="_blank">
<img
src="/src/assets/react.svg"
className="logo"
alt="Visible in dev"
width="25"
height="25"
style={{ border: "1px solid green" }}
/>
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.jsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</div>
);
}
export default App;
So to those who find this question i've put here, the problem was from 2 different sources for me.
First, The version of the image used for the codebuild was defaulting to version 1 every time I redeployed as i hadn't chosen a specific image to use.
Secondly, this pipeline function isn't made for what i wanted it to do. For context, if you are wanting to build a source => build => deploy framework, make sure to use aws_codePipeline.Pipeline to build out each step.
You can find good examples of this in their documentation.
I'm currently learning about npm and have npm installed Vue.js. However, this does not work when I try to use create a simple vue instance from my view. It works however when I enter a CDN link in the script source.
So this works:
<script src="https://cdn.jsdelivr.net/npm/vue#2.6.12/dist/vue.js"></script>
<div id="app">
{{ message }}
</div>
//This works fine
<script src="node_modules/vue/dist/vue.js"></script>
<div id="app">
{{ message }}
</div>
//This does NOT work
My package.json looks like this:
"dependencies": {
"express": "^4.17.1",
"vue": "^2.6.12"
}
So what am I missing in order to get the vue from the node_modules folder?
You don't use relative paths with node_modules.
Try using an import statement:
import Vue from 'vue'
new Vue({ el: '#app' })
Or better yet, use the Vue CLI and run vue create <project-name>. This way you can use Single-File-Components and all the scaffolding is handled for you.
I already try a lot of things and read a topic about prettier/prettier and eslint error when using nuxtjs this is my first time using nuxt but I can't seem to make it work. I try to install npm i eslint-config-prettier but nothing happen, I tried this code too npm run lint -- --fix it fix the code but when I add a new code it still give me the error.
I try this topic but still not solved:
eslint-and-prettier-battle-for-supremacy
add a lint:fix command to package.json
this is the screenshot I got:
This the error message that i got
this is my carousel code:
<template>
<h1>Test boy</h1>
</template>
<style scoped>
h1 {
color: black;
}
</style>
can someone help me?
Recently I was watching some video tutorials on youtube and came across this JADE thing, how do I install and use it for my web development?
I googled it around but didn't find a proper site that teaches step-by-step to proceed with. And the site jade-lang.com is not available. I did this from websites but node.js is throwing some errors. screenshot below:
first jade is deprecated and new name for jade is pug for more information about this check this link
pug documentation
second to install pug write this command npm install pug -g after you install pug create a new folder to your project and create a file inside your project file.pug and right click on your folder project + shift
and open command window here and write this command pug file.pug after you write this command it will generate a new file file.html
Third write this command pug input.pug input.html --watch --pretty
--watch to compile your code after saving in file.pug
--pretty to write a code with format of html(organized code) not minimized code
to write a tag in pug write the name of tag like
html tag and we will compile to <html></html>
a(href='#' target='_blank') link compile to link
a(href='#' target=''): img(src='' alt='') compile to <img src="" alt=""/>
to write a comment // this is a comment compile to <!-- this is a comment -->
to write class name and content for tag for example p.demo this is a paragraph compile to <p class="demo"> this is a paragraph</p>
to write id and content for tag for example p#demo this is a paragraph compile to <p id="demo"> this is a paragraph</p>
to write a function
mixin list
ul
li foo
li bar
li baz
to use this function write the name of function +list and will compile to
<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
to include file write include file_name
Finally this is a example for pug code
html
head
title Hello
link(href='' rel='stylesheet' type='text/css')
body
//this is a comment
p.item hello
p#item
br/
a(href='#' target=''): img(src='' alt='')
// to start a new line
|
|
a(href='google.com') Google
// write a function
mixin list
ul
li foo
li bar
li baz
// use function
+list
// include file
include content
For more information about pug check this link pug full documentation
Jade is now called "pug".
npm install pug -g
Here you will find how to use it if you scroll down:
https://www.npmjs.com/package/pug
I have deployed an app at heroku.
Everything works fine, locally. However, when deployed heroku can't find two img. index.html contains exactly this, at different places :
FOUND <img src="img/bamboo-black.png" height="27"> <div class="loaderWrap">
NOT FOUND <img class="loader" src="img/ajax-loader-black.gif"></div>
NOT FOUND <img src="img/person-placeholder.jpg" class="mainPicture" width="150">
Why would it work locally and fail on heroku ? I don't understand.
Did you commit those two files to the repo?
Do a git status and see if they're in the 'new files' section.
If you've committed the files, then login to the Heroku dyno and verify they are there.
$ heroku run bash
You can also try a restart.
$ heroku restart
Fixed it.
For those who might encounter the same problem someday : i used a CDN (cloudinary)
I replaced :
<div class="loaderWrap"> <img class="loader" src="img/ajax-loader-black.gif"></div>
By this :
var $loader = $.cloudinary.image( LJ.cloudinary.loader_id, LJ.cloudinary.displayParamsLoader );
$loader.appendTo( $('.loaderWrap') );
It works fine now.