[help] use with react, import issue
See original GitHub issueFirst of all, WELL WORK! 👍 👍 👍
Description
I want to use ami with React, and select react-react-app as a starter.
but when require ami,
import AMI from 'ami.js'
I got unexpected token import
, Becuase the file at src/
is not CommonJS style
.
So, I just use babel to transform src/
to lib/
,and set mian
value at package.json
to lib/ami.js
。
babel src -d lib
Now, the import
operation is OK, but some code like:
import coreIntersections from '../../src/core/core.intersections'
cause invoke error. Because ../../src/core/core.intersections
is a absolute path, take the invoke logic to src
path instead of lib
.
suggestion
- transform the es6 code to CommonJS, example like react-router
- don’t invoke modules with
../../src/core/*
style, it’s just like absolute path.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
React File Import Issue - Stack Overflow
I'm very new to React and ran into an issue when trying to import a "sub-component", for lack of a better word. In...
Read more >Importing and Exporting Components - React Docs
Import it in the file where you'll use the component (using the corresponding technique for importing default or named exports). Here both Profile...
Read more >Quick Fix command for missing React component ... - GitHub
Try to use Quick Fix on the SampleComponent to automatically add its import; Only the fix to import React is available initially -...
Read more >You no longer need to import React from 'react'
If you use React, import React from 'react' is the first thing that you write in your code but if you have created...
Read more >ReactJS | Importing and Exporting - GeeksforGeeks
Thus, it is possible to import/export React Components and is one of the basic operations to be performed. In React we use the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes I se what you mean - getting rid of
src
in../../src/core/core.intersections
would make it work for you, right?actually having
src
when importing module doesn’t make sense and should be removed.import coreIntersections from '../../src/core/core.intersections'
should be'import coreIntersections from '../core/core.intersections'
.I’d like to keep it all
es6
rather than common as it is a standard and there should always be a way for people to use the library if it follows standards properly.What you you think?
Looking good to me thanks!