What do I need to do to import and use the Moip SDK correctly without error?
I am trying to integrate into my Angular application the Moip API using https://github.com/moip/moip-sdk-node.
When running the code below in my moip-api.service.ts file, an error is occurring.
import moipSdk from 'moip-sdk-node'
const moip = moipSdk({
token: 'your-access-token',
key: 'your-access-key',
production: false
});
In Visual Studio Code:
Try npm install #types/moip-sdk-node if it exists or add a new
declaration (.d.ts) file containing declare module 'moip-sdk-node';
In cmd.exe Running ng serve:
ERROR in ./node_modules/moip-sdk-node/dist/client/api.js Module not
found: Error: Can't resolve '../../package' in
'C:\dev\allclinics\node_modules\moip-sdk-node\dist\client' ERROR in
./node_modules/moip-sdk-node/dist/client/api_assinaturas.js
Related
Background
I'm creating an application that allows users to interact with basic web controls which output controller events through emulated virtual controllers (so user slides a slider, and that manifests in the system as an axis being changed on a virtual controller). I'm building this as an Electron app which contains an Angular CLI project.
To get the virtual controller functionality I'm consuming a project which wraps native virtual controller functionality and exposes it for node applications. (node-ViGEmClient)
Issue
I've created the basic project and imported the required package. However, when I build the project with ng-build I get the following errors:
./node_modules/vigemclient/lib/DS4Controller.js:1:20-59 - Error: Module not found: Error: Can't resolve '../build/Release/vigemclient' in 'C:\Develop\WebDev\Node\deskpad\node_modules\vigemclient\lib'
Tracking these errors down, they come from files like this:
Looking further into the package's structure, it should be looking for vigemclient.node in build/Release, and that file is indeed present:
I feel like there is some configuration I need to do in Angular (something to do with webpack?) but I don't know what it is. Can anyone point me in the right direction?
In case anyone wants to poke around with my (currently barebones) project, it's located here: DeskPad
Project Details
Node: v16.17.0
Angular CLI: v14.2.3
REPRODUCING
Create a new Angular CLI project:
ng new testProj
Install ViGEmClient package:
npm install vigemclient
Note: This seems to require libraries related to building C++ code which are prompted during the initial install for Node.
Add this line to tsconfig.json to allow synthetic default imports:
"allowSyntheticDefaultImports": true,
Reference the package in the default app component so that it is used:
import { Component } from '#angular/core';
import ViGEmClient from 'vigemclient';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'vigTestAngular';
client = new ViGEmClient();
}
Attempt to build the project with the command "npm run build"
Outcome: These errors should be produced:
./node_modules/vigemclient/lib/DS4Controller.js:1:20-59 - Error: Module not found: Error: Can't resolve '../build/Release/vigemclient' in 'C:\Develop\WebDev\Node\vigTestAngular\node_modules\vigemclient\lib'
./node_modules/vigemclient/lib/ViGEmClient.js:1:20-59 - Error: Module not found: Error: Can't resolve '../build/Release/vigemclient' in 'C:\Develop\WebDev\Node\vigTestAngular\node_modules\vigemclient\lib'
./node_modules/vigemclient/lib/ViGEmTarget.js:5:20-59 - Error: Module not found: Error: Can't resolve '../build/Release/vigemclient' in 'C:\Develop\WebDev\Node\vigTestAngular\node_modules\vigemclient\lib'
./node_modules/vigemclient/lib/X360Controller.js:1:20-59 - Error: Module not found: Error: Can't resolve '../build/Release/vigemclient' in 'C:\Develop\WebDev\Node\vigTestAngular\node_modules\vigemclient\lib'
I was experiencing the exact same error with a native package. In my case this is also an Electron app with angular ~14.2 on Windows.
A friend pointed me to the problem: I was importing the native package from the angular web app code (renderer), but apparently when using native packages in an Electron application, they can only be imported in the Electron main process (main.ts).
Hope this helps!
I'm trying to make a Vue project and use an npm package for connecting to the retroachievements.org api to fetch some data, but I'm getting an error. Here's my process from start to finish to create the project and implement the package.
Navigate to my projects folder and use the vue cli to create the project: vue create test. For options, I usually chose not to include the linter, vue version 2, and put everything in package.json.
cd into the /test folder: cd test and install the retroachievements npm package: npm install --save raapijs
Modify App.vue to the following (apologies for code formatting, not sure why the post isn't formatting/coloring it all properly...):
const RaApi = require('raapijs');
export default {
name: 'App',
data: () => ({
api:null,
user: '<USER_NAME>',
apiKey: '<API_KEY>',
}),
created() {
this.api = new RaApi(this.user, this.apiKey);
},
}
run `npm run serve' and get the error:
ERROR in ./node_modules/raapijs/index.js 2:14-30
Module not found: Error: Can't resolve 'https' in 'C:\Projects\Web\test\node_modules\raapijs'
I'm on Windows 10, Node 16.17.0, npm 8.15.0, vue 2.6.14, vue CLI 5.0.8, raapijs 0.1.2.
The first solution below says he can run it without error but it looks like the exact same code as I'm trying. Can anyone see a difference and a reason for this error?
EDIT: I reworded this post to be more clear about my process and provide more info, like the versions.
This solution works for me. I installed raapijs with npm install --save raapijs command. Then in my Vue version 2 component I used your code as follow:
const RaApi = require('raapijs');
export default {
data: () => ({
api: null,
user: '<USER_NAME>',
apiKey: '<API_KEY>',
}),
created() {
this.api = new RaApi(this.user, this.apiKey);
},
};
It seems the raapijs package was designed to be used in a Node environment, rather than in Vue's browser based environment, so that's the reason I was getting an error. The package itself was looking for the built in https package in Node, but since it wasn't running in Node, it wasn't finding it.
So I solved my problem by looking at the package's github repo and extractingt he actual php API endpoints that were being used and using those in my app directly, rather than using the package wrapper. Not quite as clean and tidy as I was hoping but still a decent solution.
I'm writting a NodeJS application where I want to use worker_threads to get rid of a blocking I/O call _mfrc522.findCard() by a third party module (mfrc522-rpi) which delays the request handling of a WebApi in the same application.
When I try to reference the worker_threads module in my TypeScript file I get the following WebPack error message:
const { Worker } = require('worker_threads');
ERROR in ./core/command-processing/rfid-command-processor.ts
Module not found: Error: Can't resolve 'worker_threads' in '/home/pi/leabox/src/core/command-processing'
# ./core/command-processing/rfid-command-processor.ts 11:19-44
# ./core/leabox-controller.ts
# ./index.ts
But I'm able to execute the following command directly:
node -e "require('worker_threads'); console.log('success');
Output:
success
Node version: 11.15.0
WebPack version: 4.41.2
TypeScript version: 3.6.4
Activating experimental worker support for node.js via the command line before starting the application solved the issue for me:
export NODE_OPTIONS=--experimental-worker
Please check this thread for further information.
I am using the api from musixmatch-sdk and have an error by building my project with webpack.
I am using webpack 2, react, node.
The default import on the musixmatch site is:
var MusixmatchApi = require('../../build/javascript-client/src/index');
But this does't work and getting this error:
ERROR in ./build/javascript-client/src/index.js<br/>
Module not found: Error: Can't resolve 'ApiClient' in '/Users/myname/lyrix/build/javascript-client/src'<br/>
# ./build/javascript-client/src/index.js 28:4-2099<br/>
# ./src/server.js
So I have wrote it with an absolute path like:
const MusixmatchApi = require(path.join(__dirname,'../build/javascript-client/src/index'));
This works in development mode of webpack, but i get this warning:
WARNING in ./src/server.js
33:20-102 Critical dependency: the request of a dependency is an expression
# ./src/server.js
So if I want to build the production project i get the error:
Error: Cannot find module "."<br/>
at /Users/myname/lyrix/src/server-es5.js:1:16712<br/>
at Object.<anonymous> (/Users/myname/lyrix/src/server-es5.js:1:16782)
Can you please help me?
Hey thanks for helping me out.
I install google-cloud with npm, just like:
npm install --save google-cloud
then I implement in my code like that:
var gcloud = require('google-cloud')({
projectId: "czernitzki-148120",
keyFilename: './service.json'
});
I created a key on a new Service Account that has Owner access rights and put the file in service.json. service.json is in the same directory as the file that has the code above. After I start the application, it blows up when it reaches the code from above
Error in ./~/google-cloud/~/protobufjs/dist/ProtoBuf.js
Module not found: [CaseSensitivePathsPlugin] `C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\ByteBuffer\dist\ByteBufferAB.js` does not match the corresponding path on disk `bytebuffer`.
# ./~/google-cloud/~/protobufjs/dist/ProtoBuf.js 25:8-39
Error in ./~/google-cloud/~/bytebuffer/dist/ByteBufferAB.js
Module not found: [CaseSensitivePathsPlugin] `C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\Long\dist\Long.js` does not match the corresponding path on disk `long`.
# ./~/google-cloud/~/bytebuffer/dist/ByteBufferAB.js 26:8-33
Error in ./~/google-cloud/~/JSONStream/index.js
Module parse failed: C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\JSONStream\index.js Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (1:0)
# ./~/google-cloud/~/#google-cloud/prediction/src/model.js 25:17-38
Error in ./~/google-cloud/~/osenv/osenv.js
Module not found: 'child_process' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\osenv
# ./~/google-cloud/~/osenv/osenv.js 3:11-35
Error in ./~/google-cloud/~/uid-number/uid-number.js
Module not found: 'child_process' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\uid-number
# ./~/google-cloud/~/uid-number/uid-number.js 9:20-44
Error in ./~/google-cloud/~/node-pre-gyp/lib/info.js
Module not found: 'aws-sdk' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\node-pre-gyp\lib
# ./~/google-cloud/~/node-pre-gyp/lib/info.js 14:14-32
Error in ./~/google-cloud/~/node-pre-gyp/lib/publish.js
Module not found: 'aws-sdk' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\node-pre-gyp\lib
# ./~/google-cloud/~/node-pre-gyp/lib/publish.js 17:14-32
Error in ./~/google-cloud/~/node-pre-gyp/lib/testbinary.js
Module not found: 'child_process' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\node-pre-gyp\lib
# ./~/google-cloud/~/node-pre-gyp/lib/testbinary.js 10:9-33
Error in ./~/google-cloud/~/node-pre-gyp/lib/unpublish.js
Module not found: 'aws-sdk' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\node-pre-gyp\lib
# ./~/google-cloud/~/node-pre-gyp/lib/unpublish.js 15:14-32
Error in ./~/google-cloud/~/node-pre-gyp/lib/util/compile.js
Module not found: 'child_process' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\node-pre-gyp\lib\util
# ./~/google-cloud/~/node-pre-gyp/lib/util/compile.js 9:9-33
Error in ./~/google-cloud/~/google-auth-library/lib/auth/googleauth.js
Module not found: 'child_process' in C:\Users\phili\Documents\GitHub\venos\node_modules\google-cloud\node_modules\google-auth-library\lib\auth
# ./~/google-cloud/~/google-auth-library/lib/auth/googleauth.js 21:11-35
I am using React with create-react-app. I've tested it on Windows and the Google Compute Engine. It didn't work on both.
I followed the guide from https://github.com/GoogleCloudPlatform/google-cloud-node and https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/0.3.0/storage.
How can I solve this issue?
google-cloud is a back-end module, and should be used with Node.js, not the front-end.
As mentioned by the comments on this similar question, use Google's front-end api client.
You need to do npm install for the modules that are not found,like the following :
npm install aws-sdk
For the first two errors regarding CaseSensitivePathsPlugin,you can find the solution at Case Sensitive Paths - Webpack Plugin