Below are my codes
// config
requirejs.config({
paths: {
jquery: 'library/jquery',
jsBarcode: 'library/jsBarcode.all.min',
q: 'library/q.min',
},
shim: {
jsBarcode: {
deps: ['jquery'],
export: 'JsBarcode',
},
}
});
// Main entry
require(['jquery', 'q', 'jsBarcode'], function (j, q, barcode) {
window.Q = q;
console.log(barcode); // get undefined
});
Directory layout
└── webcontroller
├── bootstrap.min.css
├── image
│ └── load_trans.gif
├── scripts
│ ├── library
│ │ ├── jquery.js
│ │ ├── jsBarcode.all.min.js
│ │ └── q.min.js
│ ├── main.js
│ ├── promise_factory.js
│ ├── require.js
│ └── view.js
└── style.css
Loading sequences
The order for loading scripts is under my expectations.
Problems
However, barcode is undefined all the time.
Any one have ideas about this problem?
Updated
However, below codes can dump something out....
console.log(JsBarcode);
Fix the typo export -> exports, it must be the root cause. Also you have three excessive commas although it seems not to cause troubles. Finally there must be some global JsBarcode defined in jsBarcode.all.min.js that's why your console.log dumps it.
jsBarcode: {
deps: ['jquery'],
exports: 'JsBarcode'
}
Related
If I have the following:
├── Cargo.lock
├── Cargo.toml
├── main
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── module2
│ ├── Cargo.toml
│ └── src
│ ├── lib.rs
│ └── builder.rs
Where the Cargo.toml file in the root is the following:
[workspace]
members = [
"main",
]
I want to access a function from builder.rs in main when testing(i.e. cfg(test)), how can I do so?
Module2 is a library(it was created by running cargo new module2 --lib.
I tried the following:
// module2/builder.rs
pub fn build() { /*...*/ }
// module2/lib.rs
#[cfg(test)]
mod mock;
#[cfg(test)]
pub use mock::build;
// main/Cargo.toml
// ...
[dependencies]
module2 = { path = "../module2" }
// main.rs
#[cfg(test)]
use module2::build;
/*
...
*/
This doesn't work and I get the following error:
error[E0432]: unresolved import `module2::build`
--> main/src/main.rs:3:5
|
3 | use module2::build;
| ^^^^^^^^^^^^^^ no `build` in the root
test of module1 is not test of main: each crate gets cfg(test) turned on only when it itself is being tested, not when a dependency of it is being tested.
You can use cfg(debug_assertions) as an approximation or a custom feature.
I need your help because this is really starting to get to me.
I can't seem to solve this error with TypeORM and NestJS.
ERROR [ExceptionHandler] No repository for "CommentRepository" was
found. Looks like this entity is not registered in current "default"
connection?
The error is pretty clear but I don't understand how the config entities: [] works.
The worst thing is that before, everything was working perfectly. But after a little refactoring of my structure, it doesn't work anymore.
My folder structure :
.
├── app.module.ts
├── authentication
│ ├── auth.controller.ts
│ ├── auth.module.ts
│ ├── auth.service.ts
│ ├── dto
│ └── enums
├── common
│ ├── constants
│ ├── decorators
│ ├── enums
│ ├── exceptions
│ ├── guard
│ ├── helpers
│ ├── interceptor
│ ├── interfaces
│ ├── middlewares
│ ├── pipes
│ ├── serializers
│ ├── strategies
│ └── validations
├── config
│ ├── app
│ ├── cache
│ └── database # Here are my database config
├── database
│ ├── config.schema.ts
│ ├── factories
│ ├── migrations
│ ├── providers
│ └── seeders
├── locales
│ ├── en
│ └── fr
├── mails
│ ├── mail.module.ts
│ ├── mail.service.ts
│ ├── reset-password
│ ├── templates
│ └── verification
├── main.ts
└── models # Here are my models
├── address
├── booking
├── comment
├── company
├── container
├── listing
├── office
├── port
└── user
My database config :
...
├── config
│ ├── app
│ ├── cache
│ └── database
│ └── postgres
│ ├── config.module.ts
│ ├── config.service.ts
│ └── configuration.ts
...
My database config service and the app module
// config.service.ts
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '#nestjs/typeorm';
import { Injectable } from '#nestjs/common';
import { ConfigService } from '#nestjs/config';
#Injectable()
export class PostgresConfigService implements TypeOrmOptionsFactory {
constructor(private configService: ConfigService) {}
createTypeOrmOptions(): TypeOrmModuleOptions {
return {
type: 'postgres',
host: this.configService.get<string>('DB_HOST'),
port: this.configService.get<string>('DB_PORT'),
username: this.configService.get<string>('DB_USERNAME'),
password: this.configService.get<string>('DB_PASSWORD'),
database: this.configService.get<string>('DB_DATABASE'),
entities: ['../../models/**/entities/*.entity.{ts,js}'],
synchronize: true,
autoLoadEntities: true,
migrations: ['src/database/migrations/*.ts'],
migrationsRun: true,
cli: {
migrationsDir: 'src/database/migrations',
},
};
console.log(this.configService.get<string>('DB_HOST'));
}
}
// app.module.ts
...
imports: [
ConfigModule.forRoot({
envFilePath: [`.env.${process.env.STAGE}`],
validationSchema: configValidationSchema,
isGlobal: true,
}),
TypeOrmModule.forRootAsync({
useClass: PostgresConfigService,
inject: [PostgresConfigService],
}),
...
]
I have two projects: my-lib a Vue 3 library and my-project a Vue 3 project that uses this library.
My-lib:
I can compile the library and compile its declaration files. This what I have in the dist folder of the library:
./dist
├── demo.html
├── index.common.js
├── index.common.js.map
├── index.umd.js
├── index.umd.js.map
├── index.umd.min.js
├── index.umd.min.js.map
├── src
│ ├── components
│ │ └── book
│ │ ├── BookToolBar.d.ts
│ │ └── BookToolBar.d.ts.map
│ ├── index.common.d.ts
│ ├── index.common.d.ts.map
│ └── shared
│ └── security
│ ├── AuthenticationResult.d.ts
│ └── AuthenticationResult.d.ts.map
└── tsconfig.tsbuildinfo
This is a piece from package.json of the library:
"name": "my-lib",
"version": "0.1.0",
"private": true,
"files": [
"dist/**.*"
],
"main": "dist/index.common.js",
"unpkg": "dist/index.umd.min.js",
"types": "dist/src/index.common.d.ts",
This is a dist/src/index.common.d.ts file:
export { BookToolBar } from "#/components/book/BookToolBar";
export { AuthenticationResult } from "#/shared/security/AuthenticationResult";
My-project:
The problem is that VS code ignores my declaration files in the following code:
import { AuthenticationResult } from "my-lib";
class AuthenticationResultChild extends AuthenticationResult {...}
However, the following code works fine:
import { AuthenticationResult } from "my-lib/dist/src/shared/security/AuthenticationResult";
class AuthenticationResultChild extends AuthenticationResult {...}
Could anyone say, how to make VS code work with declarations using the first variant (import { AuthenticationResult } from "my-lib")?
ATM I have a folder in my NodeJS application where I store my JS files with a couple of functions. I require these files in my main.js at the top an use them as usual.
my-app/
├── node_modules/
├── my_jsfiles/
│ ├── functions_1.js
│ └── functions_2.js
├── package.json
└── main.js
main.js:
const myFuncs1 = require('./my_jsfiles/functions_1.js')
const myFuncs2 = require('./my_jsfiles/functions_2.js')
myFuncs1.someFuncsInside()
myFuncs2.someFuncsInside()
APPROACH: Now that I am going to use my_jsfiles in more applications I would like to make my own NodeJS module, which works so far, but I stuck at the point how I can include multiple js files instead of just calling functions from the index.js
my-app/
├── node_modules/
│ ├── my-jsfunctions/
│ │ ├── index.js
│ │ ├── functions_1.js
│ │ └── functions_2.js
├── package.json
└── main.js
main.js:
const myFuncs = require('my-jsfunctions')
//How do I call functions from functions_1.js and functions_2.js?
I know that I can export functions from the index.js
exports.someFunction = function () {
console.log("This is a message from the index.js");
}
But what is the propper way to call functions from the other files, because I do not want to have just one index.js file with million lines of code.
you just need to import all your functions into index.js file and export from there
my-app/
├── node_modules/
├── my_jsfiles/
│ ├── functions_1.js
│ └── functions_2.js
├── package.json
└── main.js
function_1.js
function functions_1_1(){
}
module.exports={functions_1_1}
function_2.js
function functions_2_1(){
}
module.exports={functions_2_1}
index.js
const {functions_1_1} = require("./function_1.js");
const {functions_2_1} = require("./function_2.js");
module.exports={functions_1_1,functions_2_1}
main.js
const {functions_1_1,functions_2_1} =require("./my_jsfiles/index.js");
functions_1_1()
functions_2_1()
you should just be able to do
const myFuncs1 = require('my_jsfiles/functions_1.js')
const myFuncs2 = require('my_jsfiles/functions_2.js')
isn't it working?
From your file index.js on my-jsfunctions, you can export function from other files like so
export * from './functions_1';
export * from './functions_2';
then you can import function
const func1 = require('my-jsfunctions').func1;
const func2 = require('my-jsfunctions').func2;
I've this error that I receive when I try to compile:
Linking CXX executable /home/atv/catkin_ws/devel/lib/atvAcrosser/main**
CMakeFiles/main.dir/src/sendToCAN.cpp.o: In function `sendCAN()':
sendToCAN.cpp:(.text+0x432): undefined reference to `sendCanMessage(CanMsg*)'
collect2: ld returned 1 exit status
make[2]: *** [/home/atv/catkin_ws/devel/lib/atvAcrosser/main] Error 1
make[1]: *** [atvAcrosser/CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
Main call the thread sendCAN [inside sendToCAN.cpp] who calls the function sendCanMessage in the external library libARV6005.a.
This is the CMakeList.txt:
include_directories(include ${catkin_INCLUDE_DIRS})
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/atvAcrosser/lib/)
add_executable(main src/main.cpp src/setupPacketProtocol.cpp src/sendToCAN.cpp)
target_link_libraries(main ${catkin_LIBRARIES} ARV6005)
This is the tree:
src
├── atvAcrosser
│ ├── CMakeLists.txt
│ ├── include
│ │ └── atvAcrosser
│ │ ├── ARV6005Lib.h
│ │ ├── localPlannerCommunication.h
│ │ ├── receiveFromCAN.h
│ │ └── setupPacketProtocol.h
│ ├── lib
│ │ └── libARV6005.a
│ ├── package.xml
│ ├── src
│ │ ├── localPlannerCommunication.cpp
│ │ ├── main.cpp
│ │ ├── sendToCAN.cpp
│ │ ├── setupPacketProtocol.cpp
sendToCAN.h
// included dependencies
#include "ARV6005Lib.h"
//=================================
// function
void sendCAN();
sendToCAN.cpp
#include "../include/atvAcrosser/sendToCAN.h"
...
void sendCAN()
{
struct CanMsg msg;
struct CanMsg msg;
int i, result;
memset((void *)&msg, 0, sizeof msg);
msg.id = 0x33;
msg.id_type = STD_ID;
msg.length = 8;
for(i=0; i<8; i++) {
msg.data[i] = i;
}
result = sendCanMessage(&msg);
}
but with this Makefile in a tutorial example it works
all: main.c
gcc -w -o TestUtility -D_REENTRANT -I../Library -pthread ./main.c ./libARV6005.a
Check that sendCanMessage(CanMsg*) is declared in ARV6005Lib.h
Check that libARV6005.a contains symbol sendCanMessage
If symbol sendCanMessage is not in libARV6005.a, find where it is and link your executable with it.
Run make VERBOSE=1, extract link command and post it here
In your CMakeLists.txt you are missing _REENTRANT and pthread. Use target_compile_definitions and target_link_libraries to add it.
The ARV6005Lib.a was written in C.
The sendToCAN.cpp has been written in Cpp.
So was sufficient
edit the file that include ARV6005Lib.h:
extern "C" {
#include "../include/atvAcrosser/ARV6005Lib.h"
}