@Import "Unexpected '@' in Program"

@import Unexpected '@' in program

From the comment of @hw731 I think you use badly @import :

old syntax to import framework :

#import <UIKit/UIKit.h>

but now, you can use the new syntax :

@import UIKit;

you need to enable theses modules to use the keyword @import (it's enable by default when you create a new project with Xcode 5) :

Sample Image

Have a look here.

Bridging header in objective C - Unexpected '@' in program

When you want to import swift classes say like (suppose in file named MySwift.swift to be dragged to the project)

@objc public class MyClass:NSObject {

}

inside an objective-c project , you shouldn't but it inside the bridge .h file but to only import this line

#import "ProjectName-Swift.h"

top of the .m file you use the class in

Xcode Unit Test build error Unexpected '@' in program

Please check if you enabled "Enable Modules" in your test target build settings.

pod spec lint error: unexpected '@' in program

I don't think Modules are turned on by default in Xcode, can you test whether adding spec.compiler_flags = "-fmodules" to turn on modules in your generated library fixes this?

Node error: SyntaxError: Unexpected token import

ES6 imports are a recently introduced feature and the current stable version of Node does not support them yet. Node.js issue tracker has an open issue for this - but until V8 and Node add support for this feature, you will need to use a transpiler (most popular one being babel) to be able to use imports.

For quickly trying out transpilation, babel provides a web based REPL. This one demonstrates your code being transpiled.

The babel project homepage points to the relevant resources for getting started with Babel and integrating it with your development workflow.

For the simplest setup, visit this setup page and select CLI in the Babel built-ins section.

This basically involves three simple steps:

  1. Install babel-cli : npm install --save-dev babel-cli babel-preset-es2015
  2. Create .babelrc configuration file: echo '{ "presets": ["es2015"] }' > .babelrc
  3. Use the installed module to transpile your source code: ./node_modules/.bin/babel src -d lib

The aforementioned setup page also illustrates how to add an npm script to simplify the last step. Alternatively you can integrate babel with your editor or build chain so that your files are automatically compiled on change.

jest unexpected token when importing css

The problem is that Jest is hitting these CSS imports and trying to parse them as if they were JavaScript.

The "Unexpected token ." message probably comes because the first line of the file it is choking on is a CSS class declaration, i.e. .datepicker: { ... }.

Anyway, as pointed out in this answer, the way to get around this is to create a file containing a module which exports an empty object. I called mine styleMock.js.

module.exports = {};

Then, you need to create a jest.config.js file in your project root and add:

module.exports = {
moduleNameMapper: {
'\\.(css|less)$': '<rootDir>/test/jest/__mocks__/styleMock.js',
}
};

The moduleNameMapper setting tells Jest how to interpret files with different extensions. In this case we simply need to point it at the empty file we just created. Obviously adjust the path to your file accordingly.

And note that you can expand the regex above for whichever file endings you need. Mine looks like:

moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/test/jest/__mocks__/fileMock.js',
'\\.(css|less)$': '<rootDir>/test/jest/__mocks__/styleMock.js',
},

where fileMock.js is identical to styleMock.js

Alternatively, you could use a module such as jest-transform-stub, which does the same thing for you.

Unexpected token 'import' error while running Jest tests?

You just need to make sure that vue-awesome will be transformed by jest, so add
following to your jest config:

transformIgnorePatterns: ["/node_modules/(?!vue-awesome)"],

which means: "Ignore everything in node_modules except for vue-awesome.

Also here is exhausive list of other issues that might cause this error: https://github.com/facebook/jest/issues/2081

Using @import in objective C in conjunction with __cplusplus

Edit:
According to the latest docs this should work now.

See this. You have to use the -fcxx-modules flag instead of the -fmodules flag, but as the official documentation suggests - EXPERIMENTAL and VERY BROKEN. I didn't manage to get it working at all... In my opinion it's better to stick with #import and #include until that feature is out of experimental stage.

From clang.llvm.org:

-fcxx-modules
Enable the modules feature for C++ (EXPERIMENTAL and VERY BROKEN).


Related Topics



Leave a reply



Submit