Cannot find module 'Scene' or its corresponding type declarations Spark AR - spark-ar-studio

Anyone has any idea why do I get these errors? It's the first time when I'm trying to write a script, do I need to setup something first? Because from what I found in their documentation, there is no need..
Cannot find module 'Scene' or its corresponding type declarations.ts(2307)
Cannot find module 'Patches' or its corresponding type declarations.ts(2307)
Cannot find module 'Diagnostics' or its corresponding type declarations.ts(2307)
Thank you for your time!
LATER EDIT: it seems that this doesn't affect the script, because I can use functions like:
Diagnostics.log('Hello world!');
or
const [directionalLight] = await Promise.all([
Scene.root.findFirst('directionalLight0')
]);
(maybe Visual Studio was waiting for a file similar to package.json from npm)

Try to reopen all SparkAR and VSCode. It's crucial to open your script from inside SparkAR, then it should create tsconfig.json with all typings you need.

Related

Pass variable into run/debug configuration arguments

I've done a fair old bit of searching, so asking here as a last resort!
I know under "File Watchers" there are variables/macros that can be passed into the arguments field like $FileName$
Can this be done with Run/Debug configurations? I've tested with the variables/macros available from File Watchers, but they just get passed directly through to my gulpfile.
If not possible, an alternate approach - is it possible to read the path that a watcher (gulp-watch) has been trigger from?
Many thanks in advance,
No, it's not possible. Generic support for using macros in run configurations was added in 2018.3 (see IDEA-74031), but it has to be implemented separately for each configuration/field. Please feel free to file a request for adding variables support to Gulp run configuration to youtrack, https://youtrack.jetbrains.com/issues/WEB

Adding JsStore in angular 6 library can't resolve file-loader

I am using JsStore with angular 6 and I am getting this error when try to import it with file-loader
" import * as workerPath from 'file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.js' ".
It show cannot find module 'file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.js'.
Adding the extra folder with worker.d.ts file doesn't help in angular library generated with the new 'ng generate library' because the library use roll-up instead of web-pack and doesnt has a file-loader. Could you suggest me another way to import jsstore.worker.js, please?
There are multiple approach to do it -
You can copy the jsstore script in a folder then supply the path of the worker to jsstore instance.
e.g -
var con = new JsStore.Instance(new Worker('path of the jsstore worker script'));
But it would be better if we can include the script directly into the code, so that webpack or any other module bundler can take care of everything. We need to find a way to do it.
Another approach would be to run jsstore without worker (i dont recommend it, as it is slower). Check out the example - https://github.com/ujjwalguptaofficial/JsStore/tree/master/examples/ts%20without%20worker
Hope this helps.

ANE Extension Context null

I am using FreshPlanet KeyboardSize ANE in my project. I have successfully added to my project but when I run
MeasureKeyboard.getInstance().setKeyboardAdjustNothing();
I get the following error.
ArgumentError: Error #3500: The extension context does not have a method with the name setKeyboardAdjustNothing.
at flash.external::ExtensionContext/_call()
at flash.external::ExtensionContext/call()
at com.freshplanet.ane.KeyboardSize::MeasureKeyboard/setKeyboardAdjustNothing()e
How can I fix this?
Thanks.
Make sure both your Application-app.xml from the src and from your bin-debug folder contain the NAME_OF_THE_EXTENSION_ID tag matching exactly what is being called in your ExtensionContext.createExtensionContext(NAME_OF_THE_EXTENSION_ID,null) inside the source code of the ANE. If they don't match you'll not be able to set the external context in the initialization. That should also match the alias from your RemoteClass descriptor before the class declaration. I hope it's helpful info.
In my case what happened was that MSVCR (Microsoft visual c++ redistribution) was missing which is required to run c++ code.
Because the code in the extension was not able to run, the app could not find any function included in the ANE.
Make sure the code of your ANE is able of running either by writing logs or by running some sample native code independently.

In Node.js, how can a module get data from an application's package.json?

I have a module. Inside it, I'd like to access data from my parent application's package.json file. What's the best practice way to do that?
I've done this the janky way by going up 2 levels and requiring the file (or using the nconf configuration loader).
var appdir = path.resolve(__dirname, '../../');
nconf.file('app', path.join(appdir, 'package.json'));
But that seems like it could break easily.
Also I heard about pkginfo, it will automatically grab info from my own module's package.json, but I'm looking to get data from the parent application's.
Thanks for any help!
EDIT: I suppose another way of asking is, how can I get the application's path (instead of the module path) ?
You can use
require.main.require './package'
But it'll work only if your parent application's file is in a root of it's directory.
You can also wrap it into try ... catch and add ../ to path till you find package.json.
You can read more about accessing main module here http://nodejs.org/api/modules.html#modules_accessing_the_main_module
Adding to pcru's approach, this should work:
function loadMainPackageJSON(attempts) {
attempts = attempts || 1;
if (attempts > 5) {
throw new Error('Can\'t resolve main package.json file');
}
var mainPath = attempts === 1 ? './' : Array(attempts).join("../");
try {
return require.main.require(mainPath + 'package.json');
} catch (e) {
return loadMainPackageJSON(attempts + 1);
}
}
var packageJSON = loadMainPackageJSON();
Keep in mind that this will get you the main module, which something you think is what you want , but if you're building a command line tool like I was, what you really want is to get the package.json exactly two folders above where you were installed if your tool is meant to be installed locally and called with npm run-script
As mentioned in Determine project root from a running node.js application , one of the easiest ways to get to your application path is using process.cwd(), provided you have the discipline to always start your main js program from the same directory. i.e. node app/main.js and cd app && node main.js will give different results.
Another way could be to recursively follow the references to module.parent, then read out module.filename when module.parent is undefined. This also presupposes some knowledge about your app. It won't work if the location of the main script relative to the package.json could vary. I.e. you must know if the main script is in the root of the app directory, or maybe in some sort of 'bin', 'app', or 'lib' dir. However, once you find the top-level module, you could try to locate the closest package.json using the same algorithm pkginfo uses to find the package.json for the current file.

Why can't Matlab see my function?

My function is definitely working; it's tested and was at one point being recognized.
Here's the function prototype:
function [X Y] = calculateEllipse(x, y, a, b, angle)
%# Code here
end
Here's the call I'm making from the Matlab terminal:
calculateEllipse (612, 391, 107, 60, 331)
Here's the error popping out at me:
??? Undefined function or method 'calculateEllipse' for input arguments of
type 'double'.
Now, I am 100% positive I am in the same directory as the function. I even used
addpath('C:\path-to-function')
to make sure. It's just not working, and I'm baffled.
Any help is appreciated.
To summarise other posts, here is a workflow for determining the cause of the problem.
You mistyped the name of the function. Check the function definition and make sure it really it called calculateEllipse.
You saved the function to a file named something other than the function name. Check the filename of the function and make sure it matches the function name.
The folder containing the function name isn't on the MATLAB path. There are several ways to check this. Type path to see the current path, or which calculateEllipse to find the location that MATLAB is using for that file. (If there is a problem, that last command will display 'calculateEllipse' not found.. Note that addpath does not permanently update the path, so when you close down MATLAB, the path will be reset. Use savepath for this.
The folder containing the function is a subdirectory of matlabroot. These folders are reserved for fully fledged toolboxes; bad things happen when you store your code here. See Bob's answer for more information.
Other useful things to check are:
Can you call other functions that are stored in the same folder?
If you save the function in a different folder, will it run then?
Adding to what Jeff said; another possibility is that you placed the function somewhere inside of your MATLAB installation. By default MATLAB does't re-search its own file structure for new files; it assumes that its internal file structure remains unchanging. Make sure that you're saving the file (which, as Jeff pointed out, must be named calculateEllipse.m) somewhere outside of your MATLAB installation.
See https://www.mathworks.com/help/matlab/matlab_env/toolbox-path-caching-in-the-matlab-program.html, or go to the MathWorks web site and search for
path cache
for more information.
The key to this problem is this: %Has no license available. This implies that a function in the directory of the function you are trying to use has the same name as a function in a toolbox you do not own. MATLAB by default disables the whole directory and not just the function of the same name in a toolbox you do not own. Here is an example:
files in directory:
myfunction.m
scoobydoo.m
blackman.m
If I do not own the "Signal processing toolbox," then blackman.m will disable the whole directory.
I can think of a couple of reasons this could happen.
First, as Jeff said, you could have named the file 'calcEllipse.m' instead of 'calculateEllipse.m'. In which case you need to rename the function to be the same as the m file you saved.
Second, you have not added the correct path. There is no reason for this to give an error to my knowledge otherwise. Double check that you have added the path to the m file that is being saved. An easy way to check is if you type in 'calculateEll' and then press tab, does the autocomplete work? If not you are out of the path.
Hope it is one of those thing you can quickly fix!