I have a simple import statement:
import './dataMapper' as dataMap;
I am getting an error
Module build failed: SyntaxError: data.jsx: Unexpected token (1:22)
I can't seem to figure out why. If I just plain import without "as ...", it works.
According to at least this:
http://www.sitepoint.com/understanding-es6-modules/
it is the correct syntax.
It's not the correct syntax (and it's not on the page you linked either). You'll want to have a look at http://www.2ality.com/2014/09/es6-modules-final.html for a good reference.
Your code should be
import dataMap from './dataMapper'; // to import the default
or
import * as dataMap from './dataMapper'; // to import the module object
Related
I'm trying to create a user model that uses UUID as primary key:
from src.db import db # SQLAlchemy instance
import sqlalchemy_utils
import uuid
class User(db.Model):
__tablename__ = 'user'
id = db.Column(sqlalchemy_utils.UUIDType(binary=True), primary_key=True, nullable=False)
But when I generate the migrations I receive:
File "/home/pc/Downloads/project/auth/venv/lib/python3.6/site-packages/alembic/runtime/environment.py", line 836, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/pc/Downloads/project/auth/venv/lib/python3.6/site-packages/alembic/runtime/migration.py", line 330, in run_migrations
step.migration_fn(**kw)
File "/home/pc/Downloads/project/auth/migrations/versions/efae4166f832_.py", line 22, in upgrade
sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(length=16), nullable=False),
NameError: name 'sqlalchemy_utils' is not defined`
I had try to explicity inform the module I'm using like this and use a 'internal' implementation that SQLAlchemy
Obs: If I manualy import the sqlalchemy_utils in the /migrations/version/efae4166f832_.py and remove the length that is generated automaticaly sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(length=16), nullable=False) it works fine
I generate the migrations using a generate.py script:
from src import create_app
from src.db import db
from flask_migrate import Migrate
# Models
from src.user.models.user import User
app = create_app()
migrate = Migrate(app, db)`
Obs: MySQL engine
I expect that when I generate migration it generate a user model that uses UUID implemented from SQLAlchemy Utils as primary key
You have just to add:
import sqlalchemy_utils
to your script.py.mako inside migrations folder
Thanks, Marco, but I have already fixed it. I have put the import import sqlalchemy_utils inside env.py and script.py.mako, I have also put the following function:
def render_item(type_, obj, autogen_context):
"""Apply custom rendering for selected items"""
if type_ == "type" and isinstance(obj, sqlalchemy_utils.types.uuid.UUIDType):
# Add import for this type
autogen_context.imports.add("import sqlalchemy_utils")
autogen_context.imports.add("import uuid")
return "sqlalchemy_utils.types.uuid.UUIDType(), default=uuid.uuid4"
# Default rendering for other objects
return False
Inside the env.py, and at the same file I have set render_item=render_item in the function run_migrations_online:
context.configure(
...,
render_item=render_item,
...
)
I researched to do this automatically, but I couldn't find nothing that could help me.
The order of the operations matter:
export FLASK_APP=manage.py
flask db init
Do the tutorial above
flask db migrate
flask db upgrade
Background
It would be ideal if you didn't have to go and manually edit each migration file with an import sqlalchemy_utils statement.
Looking at the Alembic documentation, script.py.mako is "a Mako template file which is used to generate new migration scripts." Therefore, you'll need to re-generate your migration files, with Mako already importing sqlalchemy_utils as part of the migration file generation.
Fix
If possible, remove your old migrations (they're probably broken anyway), and add the import sqlalchemy_utils like so to your script.py.mako file:
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils #<-- line you add
${imports if imports else ""}
then just rerun your alembic migrations:
alembic revision --autogenerate -m "create initial tables"
when you go to look at your migration file you should see sqlalchemy_utils already imported via the mako script.
hope that helps.
Adding import sqlalchemy_utils in the script.py.mako file will automatically import this line on all the migration files that are generated and resolve the issue.
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
${imports if imports else ""}
Add the import sqlalchemy_utils line to the newly-created migrations/versions/{hash}_my_comment.py file. However, this will only fix the problem for that specific step of the migration. If you expect that you'll be making lots of changes to columns which reference sqlalchemy_utils, you should probably do something more robust like Walter's suggestion. Even then, though, it looks like you may need to add code to properly deal with each column type you end up using.
NB: Despite seeing the suggestion in multiple places of just adding the import line to the script.py.mako file, that did not work for me.
I am trying to follow along the udemy tutorial and ran into the following error:
Bokeh Error
attempted to retrieve property value for property without value specification in the html by running the code below.
Does anyone have a clue as why it happened? Thanks!!
from bokeh.plotting import figure
from bokeh.io import output_file, show, gridplot
#from bokeh.sampledata.periodic_table import elements
from bokeh.models import Range1d, PanTool, ResetTool, HoverTool,
ColumnDataSource, LabelSet
import pandas
from bokeh.models.annotations import Span#assess object within
annotations
#prepare the output file
output_file("layout.html")
x1,y1=list(range(0,10)),list(range(10,20))
#create a new plot
f1=figure(width=250, plot_height=250, title="Circles")
f1.circle(x1, y1, size=10, color="navy", alpha=0.5)
#create a span annotation (a vertical reference line)
span_4=Span(location=4,dimension='height',line_color='grenn',
line_width=2)
#define where to add the span_4 object instance, add_layout method
f1.add_layout(span_4)
#create a box annotation
box_2_6=BoxAnnotation(left=2,right=6,fill_color="firebrick",
fill_alpha=0.3)
f1.add_layout(box_2_6)
#show the results
show(f1)
It appears to be because of a typo - line_color='grenn' should be line_color='green'. You're right that it's an unhelpful error message though. I'll try to open a GH issue about it.
I'm trying to use react-native-vector-icons with ES6 in React Native, but unfortunately I'm having trouble importing the icons. Their documentation still uses the old require statement, so I don't think it's helpful.
This is my import:
import {Ionicons} from './node_modules/react-native-vector-icons/Ionicons.js';
This is my usage:
<Ionicons name="ios-book" color="#4F8EF7" />
The error I receive is:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
It's clear that Ionicons is undefined, so I'm aware that fundamental about the import statement is wrong.
import Ionicons from 'react-native-vector-icons/Ionicons';
import {x} from 'abc'; translates to var x=require('abc').x, not to var x=require('abc').
So what about :
import * as Ionicons from './node_modules/react-native-vector-icons/Ionicons.js';
I ended up using an import statement as follows:
import {default as Icon} from '../node_modules/react-native-vector-icons/Ionicons';
This is because after I followed #Olivier's advice, I ended up with an object that contained a number of properties and I couldn't just use <Icon> as a component, but I discovered that <Icon.default> worked.
Thanks to all who answered!
I am getting the below error when in import a custom jar.
require 'java'
require '/path/custom.jar'
java_import 'com.foo.bar'
The error reported is:
cannot import class com.foo.bar' asbar'
I am trying to built a custom logstash input plugin.
as it says because java_import 'com.foo.bar' is likely not a class-name, so you need to specify a (qualified) class-name or you can import the whole package with a java_package declartion
if 'com.foo.bar' is a "valid" Java class-name (which is quite bad practice) it simply won't work since in Ruby constant names start with upper-case, you will be left with doing the import into the current name space (module) on your own e.g. : Bar = Java::com.foo.bar
I need to use the EqualsOps (===) from scalaz, but importing scalaz.Scalaz._ gives me a naming conflict with anorm's get method.
Here is the compilation error:
reference to get is ambiguous;
[error] it is imported twice in the same scope by
[error] import scalaz.Scalaz._
[error] and import anorm.SqlParser._
How can I bring === into scope without causing the conflict with anorm?
Remove import scalaz.Scalaz._
Assuming you are comparing primitives,
import scalaz._
import std.anyVal._
import syntax.equal._
If it is something else, say strings, replace std.anyVal._, with std.string._.
Essentially, the first line gives you the various scalaz types (if you don't want this, replace std with scalaz.std, and syntax with scalaz.syntax).
Line 2 gives you the implicit conversions for the primitives. That lets you treat primitives as Equal, or actually as any of the other scalaz typeclasses, (Monoid, etc.)
Line 3 gives you EqualOps, which enables you to use the === syntax with things that can be Equal.
Hope that helps