I'm getting an error that looks like it's unable to resolve my import to my other module.
Running rollup -c I'm getting the following error
(!) Unresolved dependencies
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency
components/main/view (imported by src\index.js)
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
C:\Users\n88040\AppData\Roaming\npm\node_modules\rollup\dist\rollup.js (guessing 'View')
src/index.js
import View from 'components/main/view`;
View();
src/components/main/view.js
const View = () => console.log('foo');
export default View;
See https://rollupjs.org/guide/en#es-module-syntax
You have to import local dependencies with a leading period as otherwise it will be interpreted as an external dependency:
import View from './components/main/view';
Related
My project has 3 sub-project including
dart_server
flutter_app
share
The share project is about objects, config, and paths, ... which was used in the dart_server and flutter_app projects.
In the share project. Some objects contain a package used for the flutter like the [get][1] package and this object is used for both projects (dart_server and flutter_app). When using this object in the dart_server project, it will error and the terminal will show an error too long.
error example:
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:299:35: Error: Type 'Offset' not found.
void addPosition(Duration time, Offset position) {
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:317:3: Error: Type 'Offset' not found.
Offset _previousVelocityAt(int index) {
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:24:58: Error: Undefined name 'Offset'.
static const Velocity zero = Velocity(pixelsPerSecond: Offset.zero);
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:27:9: Error: 'Offset' isn't a type.
final Offset pixelsPerSecond;
^^^^^^
This can reproduce by creating a dart server project and import any package for the flutter like [get][1] in the file that will run and run this server by dart run.
How to use this object that contains packages for the flutter app?
i try use #import is not working。
// a.less
.hello{width:100px;height:100px;background:blue;}
// index.less
#import './a.less'
// App.jsx
import './index.less';
<div styleName="hello"></div>
ERROR:
ERROR in ./src/App.jsx
Module build failed: Error: D:/workspace_js/react-redux-boilerplate/src/App.jsx: Could not resolve the styleName 'hello'.
at styleNameValue.split.filter.map.styleName (D:\workspace_js\react-redux-boilerplate\node_modules\babel-plugin-react-css-modules\dist\getClassNam
e.js:83:15)
at Array.map (<anonymous>)
at exports.default (D:\workspace_js\react-redux-boilerplate\node_modules\babel-plugin-react-css-modules\dist\getClassName.js:66:6)
at exports.default (D:\workspace_js\react-redux-boilerplate\node_modules\babel-plugin-react-css-modules\dist\resolveStringLiteral.js:27:56)
at PluginPass.JSXElement (D:\workspace_js\react-redux-boilerplate\node_modules\babel-plugin-react-css-modules\dist\index.js:183:46)
at newFn (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\visitors.js:276:21)
at NodePath._call (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\path\context.js:76:18)
at NodePath.call (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\path\context.js:48:17)
at NodePath.visit (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\path\context.js:105:12)
at TraversalContext.visitQueue (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\context.js:150:16)
at TraversalContext.visitMultiple (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\context.js:103:17)
at TraversalContext.visit (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\context.js:190:19)
at Function.traverse.node (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\index.js:114:17)
at NodePath.visit (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\path\context.js:115:19)
at TraversalContext.visitQueue (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\context.js:150:16)
at TraversalContext.visitSingle (D:\workspace_js\react-redux-boilerplate\node_modules\babel-traverse\lib\context.js:108:19)
# ./src/index.jsx 14:0-24 28:2-30:4 28:29-30:3
# multi webpack-hot-middleware/client?reload=true react-hot-loader/patch webpack/hot/only-dev-server ./src/index.jsx
this is test demo : git#github.com:ganxunzou/react-redux-boilerplate.git
test setp:
clone git#github.com:ganxunzou/react-redux-boilerplate.git
git checkout css-module-less-postcss
npm i
npm run dev
try use #import is not working。
Mentioned error can be caused by different factors. Firstly, provided webpack.config does not include any loader for .less css-files, so ensure to add appropriate loader into config: https://github.com/webpack-contrib/less-loader
Secondly, styles can be wrapped in independent namespaces, which is useful to avoid collisions between components - so ensure, that generated scope is used property
Recently I spent quite some time to figure it out the issue with my unit test. The error that I saw in my unit test is :
Ambiguous type name 'AssetIdentifier' in 'UIImage'
This is the complete code :
import XCTest
import module
#testable import module
class VoucherOptionsViewControllerTests: XCTestCase {
lazy var result = ""
class VoucherOptionsViewControllerMock: VoucherOptionsViewController {
var result = ""
override func showOverlayView(title: String, message: String, assetIdentifier: UIImage.AssetIdentifier) {
self.result = "lalalala"
}
}
}
AssetIdentifier is an enum in UIImage extension
I tried the suggestion listed in:
Ambiguous type name error
However, it returns me with a different error on the controller:
'AssetIdentifier' is inaccessible due to 'internal' protection level
I've tried to clean and rebuild but it returns the same error.
I think your issue lays in the double import of the module module.
import module
#testable import module
By importing it twice you give the compiler two (identical) versions of every type and function defined in module. That's why it's complaining about the ambiguity of AssetIdentifier, there's two of those and it doesn't know which to pick.
The right thing to do would be to remove import module though.
The #testable import statement allows you to import a module in your test target and to gain access to the types and functions defined internal as well as public.
When you add the #testable attribute to an import statement for a module compiled with testing enabled, you activate the elevated access for that module in that scope. Classes and class members marked as internal or public behave as if they were marked open. Other entities marked as internal act as if they were declared public.
Source.
If you do that you'll see that you won't have ambiguity issues and you won't need to move the UIImage extension in the test target. As #JonReid rightfully pointed out in his comment "Production code should remain in your production target".
Hope this helps.
Although that thread does not give the real answer, it gives great clue about the issue. So the fix that I found is by removing :
#testable import module
I keep the UIImage extension in the test module so the compiler does not complain.
For a project, I'm importing a library but I don't use any of the classes in it directly. The goal is to fetch a ClassMirror at runtime to create an instance from it. So I have something like:
import 'controllers.dart';
main() {
ClassMirror controller = getClassFromString(libraryName: 'deck_app', className: 'HomeController');
InstanceMirror instance = controller.newInstance(new Symbol(''), []);
instance.reflectee.sayHey();
}
This gives me an "unused import" error. Idk if this is to be considered a bug. So I'm asking you: do you think this is to be considered as a bug? If not, is there a way I could suppress unused import errors?
What's weird is I thought Dart would tree-shake the source and remove the unused import's code, but it does not. The library is properly imported and available.
The unused import is just a conclusion from the static analyzer. You can ignore it or add a dummy statement to silence the analyzer. This has no effect when you run the application.
package com.scheduler.process;
public class Process {
public enum state {
NOT_SUBMITTED, SUBMITTED, BLOCKED, READY, RUNNING, COMPLETED
}
private state currentState;
public state getCurrentState() {
return currentState;
}
public void setCurrentState(state currentState) {
this.currentState = currentState;
}
}
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
Modified the example to try and direct to the issue. I cannot change the state on this code. Eclipse suggests importing Process.state like I had on my previous example, but this doesn't work either. This allows state s = state.READY but the call to p.setCurrentState(s); fails as does p.setCurrentState(state.READY);
Problem continued.... Following Oleg's suggestions I tried more permutations:
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.*;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
public state s = Process.state.READY;
p.setCurrentState(s);
p.setCurrentState(state.READY);
}
Okay. It's clear now that I'm a candidate for lobotomy.
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
public void doStuff(){
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
}
I needed to have a method in the class--but we're still missing something (probably obvious) here. When I go via the command line and run javac on the Machine class AFTER compiling Process, I still get the following error:
mseil#context:/media/MULTIMEDIA/Scratch/Scratch/src/com/scheduler/machine$ javac Machine.java
Machine.java:3: package com.scheduler.process does not exist
import com.scheduler.process.Process;
^
So I guess the question now becomes, what idiot thing am I missing that is preventing me from compiling this by hand that eclipse is doing for me behind the scene?
======
Problem solved here:
Java generics code compiles in eclipse but not in command line
This has just worked for me:
Download latest Eclipse
Create new project
Create two packages com.scheduler.process and com.scheduler.machine
Create class Process in package com.scheduler.process and class Machine in com.scheduler.machine and copy their contents from your post modifying them to conform to Java language syntax, like this:
Everything compiles right away.
------ to answer the previous version of the question ------
To answer the question as it is right now: you need to either
import com.scheduler.process.Process.status or import com.scheduler.process.Process.* and refer to status as just status
or
import com.scheduler.process.* or import com.scheduler.process.Process and refer to status as Process.status
------ to answer the original version of the question ------
You can't import classes that are not inside some package. You just can't. It is a compile time error to import a type from the unnamed package.
You don't need to import anything if your classes are in the same package, or if all of your classes are packageless.
If Process class was inside some package it would be possible to import just its status inner class: import a.b.c.Process.status would work just fine.
All your Windows/Linux migration issues don't have anything to do with Java and exceptions that you see. import Process.state; will produce exception on any OS because you can't import classes that don't belong to any package.
Eclipse doesn't use the Sun JDK by default. I would assume that you are using Eclipse's built in compiler as Sun's JDK and the OpenJDK are almost identical.
Java code compiles and runs exact the same on Windows and Linux most of the time (unless you use a few of the platform specific operations)
I suspect you are not building the code the same way and when you compile Machine, the Process class has not been compiled.
I suggest you use a standard build system like maven or ant and it will build the same everywhere. Failing that run Eclipse on Linux or just the same .class you use on windows as they don't need to be re-compiled in any case.
BTW: You don't need to import Process.state as it not used and its in the same package (so you wouldn't need to if you did)