I wanna import a dotile, which is on the project's root, and parse it within my middleware
something like:
import browserListDefinitions from './.browserslistrc';
but I get the TS error: TS2307: Cannot find module './.browserslistrc' or its corresponding type declarations.
I've defined the following within global.d.ts:
declare module '.browserslistrc' {}
but nothing changes. Should I install a raw loader and set it properly?
Related
I am using next/dynamic to dynamically import a component like this:
import dynamic from 'next/dynamic';
const Foo = dynamic(() => 'src/components/Foo')
I want to set the path at which my JS assets should be found dynamcically on the fly, I can't use next.config.js (nextjs is a peer dep in my package, and other complications). Is there a way to do this. I saw dynamic has an option called loader and loadableGenerated. I can't find proper docs on these options. Can these be used to modify the asset path on the fly?
I installed bootstrap-colorpicker npm package and I'm trying to import to my meteor app.
I did read "Using npm packages" and I tried to use their example: "import moment from 'moment';". but the problem is the there is a hyphen/dash in the middle of the name and it throws an error.
where should I look in the package to know how to import a npm package?
here is what i did:
import bootstrap-colorpicker from 'bootstrap-colorpicker';
Template.Test.onRendered(function() {
$('#m-color-picker').colorpicker();
});
I want the #m-color-picker to turn into a color picker, but it gives me error for the hyphen/dash.
You can use any name you like for the module in your code, eg
import bootstrapColorpicker from 'bootstrap-colorpicker';
or
import colorpicker from 'bootstrap-colorpicker';
Easy as that
For the second part of your question:
Usually the 'getting started' part of the README file should tell you how to import a module, although some older packages only mention how to require a package, which I presume is where you are coming from.
Quite often the default export will be what you need, so for example, referring to the momentjs web site:
var moment = require('moment');
You can usually assume this:
import moment from 'moment';
Basically this is taking the top level object from the module.
Your specific package doesn't seem to export anything, but just has some side-effects (perhaps it monkey-patches itself into jQuery?), so you can even drop the first part of the import and just say:
import 'bootstrap-colorpicker';
Some modules just seem to be invisible to Flow. For example I have react-native-overlay installed via npm into my node_modules directory but I get a whole bunch of errors like this from Flow:
[js/components/DatePickerOverlay.js:18
18: let Overlay = require('react-native-overlay');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ react-native-overlay. Required module not found
This module doesn't have types so it would be fine if I could just get Flow to ignore it entirely.
Here's my .flowconfig (based on React Native's one):
https://gist.github.com/almost/20c6caf6d18d0e5c689f
As you can see I'm on flow 0.20.1 and I have module.system=haste (as required by React Native)
I tried adding a //$FlowIgnore comment to the import lines but then Flow complains about an unneeded ignore comment! I also tried creating a react-native-flow.js.flow file with a dummy export which seemed to work at first but then after a flow restart stopped working.
Any ideas for how to either help Flow find this module or make it ignore the import line completely?
Looks like you're ignoring it here: https://gist.github.com/almost/20c6caf6d18d0e5c689f#file-flowconfig-L42-L50
If you don't mind manually typing it up, add a react-native-overlay.js to your interfaces and type up a couple signatures.
This is happening because the library doesn't exist in flow-typed.
A simple fix could be creating the following entry in the .flowconfig file:
[ignore]
<PROJECT_ROOT>/libdefs.js
[libs]
./libdefs.js
If using flowtype < 0.60.0 add in libdefs.js
// #flow
declare module "react-native-overlay" {
declare var exports: any;
}
Or if using flowtype > 0.60.0
declare module 'react-native-overlay' {
declare module.exports: any;
}
Note: any is an unsafe type so you can always take advantage of improve the definition of the library
Hope that helps,
I have the following scenario in python3
from phase_2d import phase_2d #where phase_2d is a python file phase_2d.py
I then edit this file and want to test the changes, without having to quit python and reload everything.
imp.reload(phase_2d)
returns the error 'Type:Error: reload() argument must be module'
Since you imported the phase_2d class from the module phase_2d, when you call imp.reload(phase_2d), the phase_2d being passed to the reload command is the class, not the module. In order to use the reload command, you must import the actual module, or otherwise get a reference to the module. For example, you could do something like this:
import phase_2d
from phase_2d import phase_2d as p2d
...
imp.reload(phase_2d)
Or, if you really only want to import the single class from the module, you could use the inspect module to get the parent module from the class (http://docs.python.org/2/library/inspect.html#inspect.getmodule)
import inspect
from phase_2d import phase_2d
....
imp.reload(inspect.getmodule(phase_2d))
I'm adding a reference to a funciones.dll file using
clr.AddReferenceToFileAndPath() because I couldnt get it to work other way with this file and it succesfully does it. The file is named funciones.dll and it's in the bin folder. But when I do
from funciones import *
I get "no module named funciones"
since the funciones.dll file it's a funciones.py file compiled, shouldnt the module name only be named funciones and no any other name? isnt the name the problem and it's another? I dont know what other info could be relevant here but if there is any let me know
When doing the from x import * you need to put the namespace from the dll where x is.
So if you your code looks like
namespace Foo.Bar{
//code in here
}
your ironpython code would look like
import clr
clr.AddReferenceFromFileAndPath("/path/to/dll.dll")
from Foo.Bar import *
Solved by compiling the .py file with clr.CompileModules() instead of pyc.py . The module can be imported when you compile it that way (Thanks Dino)