question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[help] use with react, import issue

See original GitHub issue

First 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

  1. transform the es6 code to CommonJS, example like react-router
  2. don’t invoke modules with ../../src/core/* style, it’s just like absolute path.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
NicolasRannoucommented, Mar 6, 2017

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?

0reactions
NicolasRannoucommented, Mar 7, 2017

Looking good to me thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found